File::BaseDir(3)
π File::BaseDir π
okay bestie, so this is a User Contributed Perl Documentation page, section 3 β and it's about File::BaseDir, the little module that lets you use the Freedesktop.org base directory specification. yes, that's a mouthful, we'll get to it. buckle up π¦
β VERSION
version 0.09
β¨ SYNOPSIS
use File::BaseDir qw/xdg_data_files/;
for ( xdg_data_files('mime/globs') ) {
# do something
}
like, that's the whole vibe check. move on π
πΈ DESCRIPTION
okay so this module is your go-to for finding directories and files the way the Freedesktop.org Base Directory Specification says you should. the spec gives you a whole mechanism for locating directories for config, application data, and cache data. the suggestion is that desktop apps β think GNOME, KDE, or Xfce platforms β follow this layout. but honestly? the same layout can just as well be used for non-GUI applications too. no gatekeeping here π«Ά
this module forked from File::MimeInfo β family tree moment.
and for the record, this module follows version 0.6 of the BaseDir specification. periodt.
π§ CONSTRUCTOR
new
my $bd = File::BaseDir->new;
literally the simplest constructor ever, bestie. it exists so you can call the functions as object oriented methods. that's it. that's the whole thing β¨
π FUNCTIONS
none of these are exported by default β but like, all of them can be exported by request, so don't panic. also there are two groups defined: :lookup and :vars. the :vars group contains all the routines with a xdg_ prefix. the :lookup group contains the routines to locate files and directories. iykyk π
π data_home
my $path = data_home(@path);
my $path = $bd->data_home(@path);
takes a list of file path elements and returns a new path by appending them to the data home directory. heads up: the new path does not need to exist β it's giving "manifesting" energy. use this when you're writing user specific application data π
example:
# data_home is: /home/USER/.local/share
$path = $bd->data_home('Foo', 'Bar', 'Baz');
# returns: /home/USER/.local/share/Foo/Bar/Baz
π data_dirs
# :lookup
my $dir = data_dirs(@path);
my $dir = $bd->data_dirs(@path);
my @dirs = data_dirs(@path);
my @dirs = $bd->data_dirs(@path);
looks for directories specified by @path in the data home and other data directories. returns a (possibly empty) list of readable directories. in scalar context only the first directory found is returned. use this to look up application data π₯
π¦ data_files
# :lookup
my $file = data_files(@path);
my $file = $bd->data_files(@path);
my @files = data_files(@path);
my @files = $bd->data_files(@path);
looks for files specified by @path in the data home and other data directories. only returns files that are readable β no shady unreadable files allowed. in scalar context only the first file found is returned. use this to look up application data π
π config_home
# :lookup
my $dir = config_home(@path);
my $dir = $bd->config_home(@path);
takes a list of path elements and appends them to the config home directory, returning a new path. the new path does not need to exist. use this when writing user specific configuration π
π config_dirs
# :lookup
my $dir = config_dirs(@path);
my $dir = $bd->config_dirs(@path);
my @dirs = config_dirs(@path);
my @dirs = $bd->config_dirs(@path);
looks for directories specified by @path in the config home and other config directories. returns a (possibly empty) list of readable directories. in scalar context only the first directory found is returned. use this to look up configuration β¨
π§ config_files
# :lookup
my $file = config_files(@path);
my $file = $bd->config_files(@path);
my @files = config_files(@path);
my @files = $bd->config_files(@path);
looks for files specified by @path in the config home and other config directories. returns a (possibly empty) list of files that are readable. in scalar context only the first file found is returned. use this to look up configuration π«Ά
π cache_home
# :lookup
my $dir = cache_home(@path);
my $dir = $bd->cache_home(@path);
takes a list of path elements and appends them to the cache home directory, returning a new path. the new path does not need to exist. cache girlies rise πΈ
π xdg_data_home
# :var
my $dir = xdg_data_home;
my $dir = $bd->xdg_data_home;
returns either $ENV{XDG_DATA_HOME} or its default value. default is $HOME/.local/share π
π xdg_data_dirs
# :var
my @dirs = xdg_data_dirs;
my @dirs = $bd->xdg_data_dirs;
returns either $ENV{XDG_DATA_DIRS} or its default value as a list. default is /usr/local/share, /usr/share π¦
β xdg_config_home
# :var
my $dir = xdg_config_home;
my $dir = $bd->xdg_config_home;
returns either $ENV{XDG_CONFIG_HOME} or its default value. default is $HOME/.config π
π xdg_config_dirs
# :var
my @dirs = xdg_config_dirs;
my @dirs = $bd->xdg_config_dirs;
returns either $ENV{XDG_CONFIG_DIRS} or its default value as a list. default is /etc/xdg β¨
π§ xdg_cache_home
# :var
my $dir = xdg_cache_home;
my $dir = $bd->xdg_cache_home;
returns either $ENV{XDG_CACHE_HOME} or its default value. default is $HOME/.cache π
πͺ NON-UNIX PLATFORMS
the use of File::Spec ensures that all paths are returned in their native formats regardless of platform. iconic, honestly. on Windows this module will use the native environment variables, rather than the default on UNIX (which is traditionally $HOME) π«Ά
bestie, important caveat: please note that the specification is targeting Unix platforms only and will only have limited relevance on other platforms. any platform dependent behavior in this module should be considered an extension of the spec. no cap π
π« BACKWARDS COMPATIBILITY
the methods xdg_data_files() and xdg_config_files() are exported for backwards compatibility with version 0.02. they are identical to data_files() and config_files() respectively, but without the "wantarray" behavior. legacy icons stay slaying π
π AUTHORS
- Jaap Karssenberg || Pardus [Larus]
<pardus@cpan.org> - Graham Ollis
<plicease@cpan.org>
π COPYRIGHT AND LICENSE
this software is copyright (c) 2003-2021 by Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself π
and that's the tea, bestie π΅ β this was perl v5.42.0, dated 2021-07-09, signing off from the File::BaseDir(3) page. go forth and locate your directories, you absolute main character π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-File-BaseDir 0.09-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms