File::XDG(3pm) | User Contributed Perl Documentation | File::XDG(3pm) |
File::XDG - Basic implementation of the XDG base directory specification
version 1.02
use File::XDG 1.00; my $xdg = File::XDG->new( name => 'foo', api => 1 ); # user config my $path = $xdg->config_home; # user data my $path = $xdg->data_home; # user cache my $path = $xdg->cache_home; # system $config my @dirs = $xdg->config_dirs_list; # system data my @dirs = $xdg->data_dirs_list;
This module provides a basic implementation of the XDG base directory specification as exists by the Free Desktop Organization (FDO). It supports all XDG directories except for the runtime directories, which require session management support in order to function.
my $xdg = File::XDG->new( %args );
Returns a new instance of a File::XDG object. This must be called with an application name as the "name" argument.
Takes the following named arguments:
The API version to use.
The path class to return
my $xdg = File::XDG->new( name => 'foo', # equivalent to path_class => 'Path::Tiny' path_class => sub { Path::Tiny->new(@_), );
# equivalent to path_class => 'Path::Class' my $xdg = File::XDG->new( name => 'foo', path_class => [ sub { Path::Class::File->new(@_) ), sub { Path::Class::Dir->new(@_) }, ], );
More strictly follow the XDG base directory specification. In particular
Historically this module has made some useful assumptions like using ";" instead of ":" for the path separator character. This breaks the spec.
my $path = $xdg->data_home;
Returns the user-specific data directory for the application as a path class object.
my $path = $xdg->config_home;
Returns the user-specific configuration directory for the application as a path class object.
my $path = $xdg->cache_home;
Returns the user-specific cache directory for the application as a path class object.
my $path = $xdg->state_home;
Returns the user-specific state directory for the application as a path class object.
[version 0.10]
my $dir = $xdg->runtime_home;
Returns the directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc) for the application.
This is not always provided, if not available, this method will return "undef".
Under strict mode, this method will only rely on the "XDG_RUNTIME_DIR" to find this directory. Under non-strict mode, system specific methods may be used, if the environment variable is not set:
my $dirs = $xdg->data_dirs;
Returns the system data directories, not modified for the application. Per the specification, the returned string is ":"-delimited, except on Windows where it is ";"-delimited.
For portability "data_dirs_list" is preferred.
[version 0.06]
my @dirs = $xdg->data_dirs_list;
Returns the system data directories as a list of path class objects.
my $dirs = $xdg->config_dirs;
Returns the system config directories, not modified for the application. Per the specification, the returned string is :-delimited, except on Windows where it is ";"-delimited.
For portability "config_dirs_list" is preferred.
[version 0.06]
my @dirs = $xdg->config_dirs_list;
Returns the system config directories as a list of path class objects.
[version 0.10]
my $exe = $xdg->exe_dir;
Returns the user-specific executable files directory "$HOME/.local/bin", if it exists. If it does not exist then "undef" will be returned. This directory should be added to the "PATH" according to the spec.
my $xdg = File::XDG->new( name => $name, api => 1 ); # recommended my $path = $xdg->lookup_data_File($filename);
Looks up the data file by searching for "./$name/$filename" (where $name is provided by the constructor) relative to all base directories indicated by $XDG_DATA_HOME and $XDG_DATA_DIRS. If an environment variable is either not set or empty, its default value as defined by the specification is used instead. Returns a path class object.
my $xdg = File::XDG->new( name => $name ); # back compat only my $path = $xdg->lookup_data_file($subdir, $filename);
Looks up the data file by searching for "./$subdir/$filename" relative to all base directories indicated by $XDG_DATA_HOME and $XDG_DATA_DIRS. If an environment variable is either not set or empty, its default value as defined by the specification is used instead. Returns a path class object.
my $xdg = File::XDG->new( name => $name, api => 1 ); # recommended my $path = $xdg->lookup_config_file($filename);
Looks up the configuration file by searching for "./$name/$filename" (where $name is provided by the constructor) relative to all base directories indicated by $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS. If an environment variable is either not set or empty, its default value as defined by the specification is used instead. Returns a path class object.
my $xdg = File::XDG->new( name => $name ); # back compat only my $path = $xdg->lookup_config_file($subdir, $filename);
Looks up the configuration file by searching for "./$subdir/$filename" relative to all base directories indicated by $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS. If an environment variable is either not set or empty, its default value as defined by the specification is used instead. Returns a path class object.
XDG Base Directory specification, version 0.7 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>
This module intentionally and out of necessity does not follow the spec on the following platforms:
There are no global data or config directories in windows so the data and config directories are empty list instead of the default UNIX locations.
The base directory instead of being the user's home directory is "%LOCALAPPDATA%". Arguably the data and config base directory should be "%APPDATA%", but cache should definitely be in "%LOCALAPPDATA%", and we chose to use just one base directory for simplicity.
Original author: Síle Ekaterin Aman
Current maintainer: Graham Ollis <plicease@cpan.org>
This software is copyright (c) 2012-2021 by Síle Ekaterin Aman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-05-29 | perl v5.34.0 |