| 1 |
NAME |
| 2 |
|
| 3 |
File::XDG - Basic implementation of the XDG base directory |
| 4 |
specification |
| 5 |
|
| 6 |
VERSION |
| 7 |
|
| 8 |
version 1.03 |
| 9 |
|
| 10 |
SYNOPSIS |
| 11 |
|
| 12 |
use File::XDG 1.00; |
| 13 |
|
| 14 |
my $xdg = File::XDG->new( name => 'foo', api => 1 ); |
| 15 |
|
| 16 |
# user config |
| 17 |
my $path = $xdg->config_home; |
| 18 |
|
| 19 |
# user data |
| 20 |
my $path = $xdg->data_home; |
| 21 |
|
| 22 |
# user cache |
| 23 |
my $path = $xdg->cache_home; |
| 24 |
|
| 25 |
# system $config |
| 26 |
my @dirs = $xdg->config_dirs_list; |
| 27 |
|
| 28 |
# system data |
| 29 |
my @dirs = $xdg->data_dirs_list; |
| 30 |
|
| 31 |
DESCRIPTION |
| 32 |
|
| 33 |
This module provides a basic implementation of the XDG base directory |
| 34 |
specification as exists by the Free Desktop Organization (FDO). It |
| 35 |
supports all XDG directories except for the runtime directories, which |
| 36 |
require session management support in order to function. |
| 37 |
|
| 38 |
CONSTRUCTOR |
| 39 |
|
| 40 |
new |
| 41 |
|
| 42 |
my $xdg = File::XDG->new( %args ); |
| 43 |
|
| 44 |
Returns a new instance of a File::XDG object. This must be called with |
| 45 |
an application name as the "name" argument. |
| 46 |
|
| 47 |
Takes the following named arguments: |
| 48 |
|
| 49 |
api |
| 50 |
|
| 51 |
[version 0.09] |
| 52 |
|
| 53 |
The API version to use. |
| 54 |
|
| 55 |
api = 0 |
| 56 |
|
| 57 |
The default and original API version. For backward compatibility |
| 58 |
only. |
| 59 |
|
| 60 |
api = 1 |
| 61 |
|
| 62 |
Recommended stable API version for all new code. |
| 63 |
|
| 64 |
name |
| 65 |
|
| 66 |
Name of the application for which File::XDG is being used. |
| 67 |
|
| 68 |
path_class |
| 69 |
|
| 70 |
[version 0.09] |
| 71 |
|
| 72 |
The path class to return |
| 73 |
|
| 74 |
File::Spec |
| 75 |
|
| 76 |
All methods that return a file will return a string generated by |
| 77 |
File::Spec. |
| 78 |
|
| 79 |
Path::Class |
| 80 |
|
| 81 |
This is the default with api = 0. All methods that return a file |
| 82 |
will return an instance of Path::Class::File and all methods that |
| 83 |
return a directory will return an instance of Path::Class::Dir. |
| 84 |
|
| 85 |
Path::Tiny |
| 86 |
|
| 87 |
This is the default with api = 1. All methods that return a file |
| 88 |
will return an instance of Path::Tiny. |
| 89 |
|
| 90 |
CODEREF |
| 91 |
|
| 92 |
If a code reference is passed in then this will be called in order |
| 93 |
to construct the path class. This allows rolling your own customer |
| 94 |
path class objects. Example: |
| 95 |
|
| 96 |
my $xdg = File::XDG->new( |
| 97 |
name => 'foo', |
| 98 |
# equivalent to path_class => 'Path::Tiny' |
| 99 |
path_class => sub { Path::Tiny->new(@_), |
| 100 |
); |
| 101 |
|
| 102 |
ARRAY |
| 103 |
|
| 104 |
Similar to passing a code reference, an array reference with two |
| 105 |
code references means the first code reference will be used for |
| 106 |
file paths and the second will be used for directory paths. This is |
| 107 |
for path classes that differentiate between files and directories. |
| 108 |
|
| 109 |
# equivalent to path_class => 'Path::Class' |
| 110 |
my $xdg = File::XDG->new( |
| 111 |
name => 'foo', |
| 112 |
path_class => [ |
| 113 |
sub { Path::Class::File->new(@_) ), |
| 114 |
sub { Path::Class::Dir->new(@_) }, |
| 115 |
], |
| 116 |
); |
| 117 |
|
| 118 |
strict |
| 119 |
|
| 120 |
[version 0.10] |
| 121 |
|
| 122 |
More strictly follow the XDG base directory specification. In |
| 123 |
particular |
| 124 |
|
| 125 |
* On Windows a an exception will be thrown when creating the |
| 126 |
File::XDG object because the spec cannot correctly be implemented. |
| 127 |
|
| 128 |
Historically this module has made some useful assumptions like |
| 129 |
using ; instead of : for the path separator character. This breaks |
| 130 |
the spec. |
| 131 |
|
| 132 |
* On some systems, this module will look in system specific |
| 133 |
locations for the "runtime_home". This is useful, but technically |
| 134 |
violates the spec, so under strict mode the "runtime_home" method |
| 135 |
will only return a path if one can be found via the spec. |
| 136 |
|
| 137 |
METHODS |
| 138 |
|
| 139 |
data_home |
| 140 |
|
| 141 |
my $path = $xdg->data_home; |
| 142 |
|
| 143 |
Returns the user-specific data directory for the application as a path |
| 144 |
class object. |
| 145 |
|
| 146 |
config_home |
| 147 |
|
| 148 |
my $path = $xdg->config_home; |
| 149 |
|
| 150 |
Returns the user-specific configuration directory for the application |
| 151 |
as a path class object. |
| 152 |
|
| 153 |
cache_home |
| 154 |
|
| 155 |
my $path = $xdg->cache_home; |
| 156 |
|
| 157 |
Returns the user-specific cache directory for the application as a path |
| 158 |
class object. |
| 159 |
|
| 160 |
state_home |
| 161 |
|
| 162 |
my $path = $xdg->state_home; |
| 163 |
|
| 164 |
Returns the user-specific state directory for the application as a path |
| 165 |
class object. |
| 166 |
|
| 167 |
runtime_home |
| 168 |
|
| 169 |
[version 0.10] |
| 170 |
|
| 171 |
my $dir = $xdg->runtime_home; |
| 172 |
|
| 173 |
Returns the directory for user-specific non-essential runtime files and |
| 174 |
other file objects (such as sockets, named pipes, etc) for the |
| 175 |
application. |
| 176 |
|
| 177 |
This is not always provided, if not available, this method will return |
| 178 |
undef. |
| 179 |
|
| 180 |
Under strict mode, this method will only rely on the XDG_RUNTIME_DIR to |
| 181 |
find this directory. Under non-strict mode, system specific methods may |
| 182 |
be used, if the environment variable is not set: |
| 183 |
|
| 184 |
Linux systemd |
| 185 |
|
| 186 |
The path /run/user/UID will be used, if it exists, and fulfills the |
| 187 |
requirements of the spec. |
| 188 |
|
| 189 |
data_dirs |
| 190 |
|
| 191 |
my $dirs = $xdg->data_dirs; |
| 192 |
|
| 193 |
Returns the system data directories, not modified for the application. |
| 194 |
Per the specification, the returned string is :-delimited, except on |
| 195 |
Windows where it is ;-delimited. |
| 196 |
|
| 197 |
For portability "data_dirs_list" is preferred. |
| 198 |
|
| 199 |
data_dirs_list |
| 200 |
|
| 201 |
[version 0.06] |
| 202 |
|
| 203 |
my @dirs = $xdg->data_dirs_list; |
| 204 |
|
| 205 |
Returns the system data directories as a list of path class objects. |
| 206 |
|
| 207 |
config_dirs |
| 208 |
|
| 209 |
my $dirs = $xdg->config_dirs; |
| 210 |
|
| 211 |
Returns the system config directories, not modified for the |
| 212 |
application. Per the specification, the returned string is :-delimited, |
| 213 |
except on Windows where it is ;-delimited. |
| 214 |
|
| 215 |
For portability "config_dirs_list" is preferred. |
| 216 |
|
| 217 |
config_dirs_list |
| 218 |
|
| 219 |
[version 0.06] |
| 220 |
|
| 221 |
my @dirs = $xdg->config_dirs_list; |
| 222 |
|
| 223 |
Returns the system config directories as a list of path class objects. |
| 224 |
|
| 225 |
exe_dir |
| 226 |
|
| 227 |
[version 0.10] |
| 228 |
|
| 229 |
my $exe = $xdg->exe_dir; |
| 230 |
|
| 231 |
Returns the user-specific executable files directory $HOME/.local/bin, |
| 232 |
if it exists. If it does not exist then undef will be returned. This |
| 233 |
directory should be added to the PATH according to the spec. |
| 234 |
|
| 235 |
lookup_data_file |
| 236 |
|
| 237 |
my $xdg = File::XDG->new( name => $name, api => 1 ); # recommended |
| 238 |
my $path = $xdg->lookup_data_File($filename); |
| 239 |
|
| 240 |
Looks up the data file by searching for ./$name/$filename (where $name |
| 241 |
is provided by the constructor) relative to all base directories |
| 242 |
indicated by $XDG_DATA_HOME and $XDG_DATA_DIRS. If an environment |
| 243 |
variable is either not set or empty, its default value as defined by |
| 244 |
the specification is used instead. Returns a path class object. |
| 245 |
|
| 246 |
my $xdg = File::XDG->new( name => $name ); # back compat only |
| 247 |
my $path = $xdg->lookup_data_file($subdir, $filename); |
| 248 |
|
| 249 |
Looks up the data file by searching for ./$subdir/$filename relative to |
| 250 |
all base directories indicated by $XDG_DATA_HOME and $XDG_DATA_DIRS. If |
| 251 |
an environment variable is either not set or empty, its default value |
| 252 |
as defined by the specification is used instead. Returns a path class |
| 253 |
object. |
| 254 |
|
| 255 |
lookup_config_file |
| 256 |
|
| 257 |
my $xdg = File::XDG->new( name => $name, api => 1 ); # recommended |
| 258 |
my $path = $xdg->lookup_config_file($filename); |
| 259 |
|
| 260 |
Looks up the configuration file by searching for ./$name/$filename |
| 261 |
(where $name is provided by the constructor) relative to all base |
| 262 |
directories indicated by $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS. If an |
| 263 |
environment variable is either not set or empty, its default value as |
| 264 |
defined by the specification is used instead. Returns a path class |
| 265 |
object. |
| 266 |
|
| 267 |
my $xdg = File::XDG->new( name => $name ); # back compat only |
| 268 |
my $path = $xdg->lookup_config_file($subdir, $filename); |
| 269 |
|
| 270 |
Looks up the configuration file by searching for ./$subdir/$filename |
| 271 |
relative to all base directories indicated by $XDG_CONFIG_HOME and |
| 272 |
$XDG_CONFIG_DIRS. If an environment variable is either not set or |
| 273 |
empty, its default value as defined by the specification is used |
| 274 |
instead. Returns a path class object. |
| 275 |
|
| 276 |
SEE ALSO |
| 277 |
|
| 278 |
XDG Base Directory specification, version 0.7 |
| 279 |
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html> |
| 280 |
|
| 281 |
CAVEATS |
| 282 |
|
| 283 |
This module intentionally and out of necessity does not follow the spec |
| 284 |
on the following platforms: |
| 285 |
|
| 286 |
MSWin32 (Strawberry Perl, Visual C++ Perl, etc) |
| 287 |
|
| 288 |
The spec requires : as the path separator, but use of this character |
| 289 |
is essential for absolute path names in Windows, so the Windows Path |
| 290 |
separator ; is used instead. |
| 291 |
|
| 292 |
There are no global data or config directories in windows so the data |
| 293 |
and config directories are empty list instead of the default UNIX |
| 294 |
locations. |
| 295 |
|
| 296 |
The base directory instead of being the user's home directory is |
| 297 |
%LOCALAPPDATA%. Arguably the data and config base directory should be |
| 298 |
%APPDATA%, but cache should definitely be in %LOCALAPPDATA%, and we |
| 299 |
chose to use just one base directory for simplicity. |
| 300 |
|
| 301 |
SEE ALSO |
| 302 |
|
| 303 |
Path::Class |
| 304 |
|
| 305 |
Portable native path class used by this module used by default (api = |
| 306 |
0) and optionally (api = 1). |
| 307 |
|
| 308 |
Path::Tiny |
| 309 |
|
| 310 |
Smaller lighter weight path class used optionally (api = 0) and by |
| 311 |
default (api = 1). |
| 312 |
|
| 313 |
Path::Spec |
| 314 |
|
| 315 |
Core Perl library for working with file and directory paths. |
| 316 |
|
| 317 |
File::BaseDir |
| 318 |
|
| 319 |
Provides similar functionality to this module with a different |
| 320 |
interface. |
| 321 |
|
| 322 |
AUTHOR |
| 323 |
|
| 324 |
Original author: Síle Ekaterin Aman |
| 325 |
|
| 326 |
Current maintainer: Graham Ollis <[email protected]> |
| 327 |
|
| 328 |
COPYRIGHT AND LICENSE |
| 329 |
|
| 330 |
This software is copyright (c) 2012-2022 by Síle Ekaterin Aman. |
| 331 |
|
| 332 |
This is free software; you can redistribute it and/or modify it under |
| 333 |
the same terms as the Perl 5 programming language system itself. |
| 334 |
|