libfile-basedir-perl-0.03/0000755000175000017500000000000010707721642014403 5ustar jdongjdonglibfile-basedir-perl-0.03/Changes0000444000175000017500000000124410707721642015675 0ustar jdongjdongRevision history for Perl extension File::BaseDir. 0.03 Wed Oct 24 2007 - Added lookup methods for files and dirs: data_home, data_files, data_dirs, config_home, config_files, config_dirs & cache_home; suggested by Matisse Enzer - Deprecated xdg_data_files and xdg_config_files; suggested by Michael Schwern - Added a bit of Win32 support - Extended tests to full coverage 0.02 Thu Sep 4 2003 - forgot to remove h2xs default "use 5.008" tag :( emergency release it is ... 0.01 Wed Sep 3 18:33:59 2003 - original version; created by h2xs 1.22 with options -AX -n File::BaseDir - Added methods for all environment variables defined by the spec libfile-basedir-perl-0.03/t/0000755000175000017500000000000010707721642014646 5ustar jdongjdonglibfile-basedir-perl-0.03/t/04_pod_ok.t0000444000175000017500000000025010707721642016604 0ustar jdongjdonguse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok( Test::Pod::all_pod_files(qw/bin lib/) ); libfile-basedir-perl-0.03/t/05_pod_cover.t0000444000175000017500000000046510707721642017322 0ustar jdongjdonguse Test::More; use File::BaseDir qw/xdg_data_dirs/; $ENV{XDG_DATA_DIRS} = join ':', 'share', xdg_data_dirs; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok( { also_private => [ qr/^_/, qr/^xdg_.*_files$/ ] } ); libfile-basedir-perl-0.03/t/02_lookup.t0000444000175000017500000000416410707721642016650 0ustar jdongjdonguse strict; use Test::More tests => 17; use File::Spec; use_ok('File::BaseDir', qw/:lookup xdg_data_files xdg_config_files/); # Initalize test data: # t/ # `-- data/ $dir[1] # |-- dir/ $dir[2] # | `-- test $file[1] # `-- test $file[0] my @dir = ('t', map File::Spec->catdir(@$_), [qw/t data/], [qw/t data dir/] ); my @file = (map File::Spec->catfile(@$_), [qw/t data test/], [qw/t data dir test/] ); mkdir $dir[1] or die $! unless -d $dir[1]; mkdir $dir[2] or die $! unless -d $dir[2]; open TEST, ">$file[0]" or die $!; print TEST "test 1 2 3\n"; close TEST; eval { chmod 0644, $file[0] }; # reset previous run open TEST, ">$file[1]" or die $!; print TEST "test 1 2 3\n"; close TEST; $ENV{XDG_CONFIG_HOME} = 'foo'; $ENV{XDG_CONFIG_DIRS} = 'bar'; $ENV{XDG_DATA_HOME} = '.'; $ENV{XDG_DATA_DIRS} = join ':', @dir; is(data_home(qw/t data test/), $file[0], 'data_home'); is(data_files(qw/data test/), $file[0], 'data_files'); is_deeply([data_files(qw/test/)], \@file, 'data_files - list'); is(data_dirs(qw/data dir/), $dir[2], 'data_dirs'); is_deeply([data_dirs(qw/data dir/)], [$dir[2]], 'data_dirs - list'); ok(!data_files(qw/data dir/), 'data_files does not match dir'); ok(!data_dirs(qw/data test/), 'data_dirs does not match file'); is_deeply([xdg_data_files(qw/test/)], \@file, 'xdg_data_files - for backward compatibility'); $ENV{XDG_CONFIG_HOME} = '.'; $ENV{XDG_CONFIG_DIRS} = join ':', @dir; $ENV{XDG_DATA_HOME} = 'foo'; $ENV{XDG_DATA_DIRS} = 'bar'; is(config_home(qw/t data test/), $file[0], 'config_home'); is(config_files(qw/data test/), $file[0], 'config_files'); is_deeply([config_files(qw/test/)], \@file, 'config_files - list'); is(config_dirs(qw/data dir/), $dir[2], 'config_dirs'); is_deeply([config_dirs(qw/data dir/)], [$dir[2]], 'config_dirs - list'); is_deeply([xdg_config_files(qw/test/)], \@file, 'xdg_config_files - for backward compatibility'); SKIP: { eval { chmod 0200, $file[0] }; # make non-readable skip "chmod not supported", 1 if -r $file[0]; is(config_files(qw/test/), $file[1], 'config_files checks for read'); } $ENV{XDG_CACHE_HOME} = 't/data'; ok(cache_home('test') eq $file[0], 'data_cache'); libfile-basedir-perl-0.03/t/01_vars.t0000444000175000017500000000275110707721642016311 0ustar jdongjdonguse strict; use Test::More tests => 12; use_ok('File::BaseDir', qw/:vars/); my $rootdir = ($^O eq 'MSWin32') ? 'c:\\' : File::Spec->rootdir(); ok(length($ENV{HOME}), 'HOME defined'); $ENV{XDG_CONFIG_HOME} = ''; ok( xdg_config_home() eq File::Spec->catdir($ENV{HOME}, qw/.config/), 'xdg_config_home default'); $ENV{XDG_CONFIG_HOME} = 'test123'; ok( xdg_config_home() eq 'test123', 'xdg_data_home set'); $ENV{XDG_CONFIG_DIRS} = ''; is_deeply( [xdg_config_dirs()], [ File::Spec->catdir($rootdir, qw/etc xdg/) ], 'xdg_config_dirs default'); $ENV{XDG_CONFIG_DIRS} = './t:foo:bar'; is_deeply( [xdg_config_dirs()], [File::Spec->catdir('.', 't'), 'foo', 'bar'], 'xdg_data_dirs set'); $ENV{XDG_DATA_HOME} = ''; ok( xdg_data_home() eq File::Spec->catdir($ENV{HOME}, qw/.local share/), 'xdg_data_home default'); $ENV{XDG_DATA_HOME} = 'test123'; ok( xdg_data_home() eq 'test123', 'xdg_data_home set'); $ENV{XDG_DATA_DIRS} = ''; is_deeply( [xdg_data_dirs()], [ File::Spec->catdir($rootdir, qw/usr local share/), File::Spec->catdir($rootdir, qw/usr share/) ], 'xdg_data_dirs default'); $ENV{XDG_DATA_DIRS} = './t:foo:bar'; is_deeply( [xdg_data_dirs()], [File::Spec->catdir('.', 't'), 'foo', 'bar'], 'xdg_data_dirs set'); $ENV{XDG_CACHE_HOME} = ''; ok( xdg_cache_home() eq File::Spec->catdir($ENV{HOME}, qw/.cache/), 'xdg_cache_home default'); $ENV{XDG_CACHE_HOME} = 'test123'; ok( xdg_cache_home() eq 'test123', 'xdg_cache_home set'); libfile-basedir-perl-0.03/t/03_OO.t0000444000175000017500000000152410707721642015652 0ustar jdongjdonguse strict; use Test::More tests => 6; use File::BaseDir; my $rootdir = ($^O eq 'MSWin32') ? 'c:\\' : File::Spec->rootdir(); my $conf = File::BaseDir->new; is(ref($conf), 'File::BaseDir', 'OO constructor works'); $ENV{XDG_DATA_DIRS} = ''; is_deeply( [$conf->xdg_data_dirs()], [ File::Spec->catdir($rootdir, qw/usr local share/), File::Spec->catdir($rootdir, qw/usr share/) ], 'xdg_data_dirs default - OO'); $ENV{XDG_DATA_HOME} = 't'; is($conf->data_dirs('data'), File::Spec->catdir(qw/t data/), 'data_dirs - OO'); is(File::BaseDir->data_dirs('data'), File::Spec->catdir(qw/t data/), 'data_dirs - Module'); is($conf->data_home('data', 'test'), File::Spec->catfile(qw/t data test/), 'data_home - OO'); is(File::BaseDir->data_home('data', 'test'), File::Spec->catfile(qw/t data test/), 'data_home - Module'); libfile-basedir-perl-0.03/Makefile.PL0000444000175000017500000000211510707721642016352 0ustar jdongjdong# Note: this file was auto-generated by Module::Build::Compat version 0.03 unless (eval "use Module::Build::Compat 0.02; 1" ) { print "This module requires Module::Build to install itself.\n"; require ExtUtils::MakeMaker; my $yn = ExtUtils::MakeMaker::prompt (' Install Module::Build now from CPAN?', 'y'); unless ($yn =~ /^y/i) { die " *** Cannot install without Module::Build. Exiting ...\n"; } require Cwd; require File::Spec; require CPAN; # Save this 'cause CPAN will chdir all over the place. my $cwd = Cwd::cwd(); CPAN::Shell->install('Module::Build::Compat'); CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate or die "Couldn't install Module::Build, giving up.\n"; chdir $cwd or die "Cannot chdir() back to $cwd: $!"; } eval "use Module::Build::Compat 0.02; 1" or die $@; Module::Build::Compat->run_build_pl(args => \@ARGV); require Module::Build; Module::Build::Compat->write_makefile(build_class => 'Module::Build'); libfile-basedir-perl-0.03/MANIFEST0000444000175000017500000000025410707721642015533 0ustar jdongjdongBuild.PL Changes configure lib/File/BaseDir.pm Makefile.PL MANIFEST This list of files META.yml README t/01_vars.t t/02_lookup.t t/03_OO.t t/04_pod_ok.t t/05_pod_cover.t libfile-basedir-perl-0.03/META.yml0000444000175000017500000000101610707721642015650 0ustar jdongjdong--- name: File-BaseDir version: 0.03 author: - 'Jaap Karssenberg ' abstract: Use the Freedesktop.org base directory specification license: perl resources: license: http://dev.perl.org/licenses/ requires: Carp: 0 Exporter: 0 File::Spec: 0 build_requires: Module::Build: 0.24 Test::More: 0 provides: File::BaseDir: file: lib/File/BaseDir.pm version: 0.03 generated_by: Module::Build version 0.2806 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 libfile-basedir-perl-0.03/lib/0000755000175000017500000000000010707721642015151 5ustar jdongjdonglibfile-basedir-perl-0.03/lib/File/0000755000175000017500000000000010707721642016030 5ustar jdongjdonglibfile-basedir-perl-0.03/lib/File/BaseDir.pm0000444000175000017500000001764710707721642017714 0ustar jdongjdongpackage File::BaseDir; use strict; use Carp; require File::Spec; require Exporter; our $VERSION = 0.03; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( vars => [ qw( xdg_data_home xdg_data_dirs xdg_config_home xdg_config_dirs xdg_cache_home ) ], lookup => [ qw( data_home data_dirs data_files config_home config_dirs config_files cache_home ) ], ); our @EXPORT_OK = ( qw(xdg_data_files xdg_config_files), map @$_, values %EXPORT_TAGS ); # Set root and home directories my $rootdir = File::Spec->rootdir(); if ($^O eq 'MSWin32') { $rootdir = 'C:\\'; # File::Spec default depends on CWD $ENV{HOME} ||= $ENV{USERPROFILE} || $ENV{HOMEDRIVE}.$ENV{HOMEPATH}; # logic from File::HomeDir::Windows } my $home = $ENV{HOME}; unless ($home) { warn "WARNING: HOME is not set, using root: $rootdir\n"; $home = $rootdir; } # Set defaults our $xdg_data_home = File::Spec->catdir($home, qw/.local share/); our @xdg_data_dirs = ( File::Spec->catdir($rootdir, qw/usr local share/), File::Spec->catdir($rootdir, qw/usr share/), ); our $xdg_config_home = File::Spec->catdir($home, '.config'); our @xdg_config_dirs = ( File::Spec->catdir($rootdir, qw/etc xdg/) ); our $xdg_cache_home = File::Spec->catdir($home, '.cache'); # OO method sub new { bless \$VERSION, shift } # what else is there to bless ? # Variable methods sub xdg_data_home { $ENV{XDG_DATA_HOME} || $xdg_data_home } sub xdg_data_dirs { ( $ENV{XDG_DATA_DIRS} ? _adapt($ENV{XDG_DATA_DIRS}) : @xdg_data_dirs ) } sub xdg_config_home {$ENV{XDG_CONFIG_HOME} || $xdg_config_home } sub xdg_config_dirs { ( $ENV{XDG_CONFIG_DIRS} ? _adapt($ENV{XDG_CONFIG_DIRS}) : @xdg_config_dirs ) } sub xdg_cache_home { $ENV{XDG_CACHE_HOME} || $xdg_cache_home } sub _adapt { map { File::Spec->catdir( split('/', $_) ) } split /[:;]/, shift; # ':' defined in the spec, but ';' is standard on win32 } # Lookup methods sub data_home { _catfile(xdg_data_home, @_) } sub data_dirs { _find_files(\&_dir, \@_, xdg_data_home, xdg_data_dirs) } sub data_files { _find_files(\&_file, \@_, xdg_data_home, xdg_data_dirs) } sub xdg_data_files { my @dirs = data_files(@_); return @dirs } sub config_home { _catfile(xdg_config_home, @_) } sub config_dirs { _find_files(\&_dir, \@_, xdg_config_home, xdg_config_dirs) } sub config_files { _find_files(\&_file, \@_, xdg_config_home, xdg_config_dirs) } sub xdg_config_files { my @dirs = config_files(@_); return @dirs } sub cache_home { _catfile(xdg_cache_home, @_) } sub _catfile { my $dir = shift; shift if ref $_[0] or $_[0] =~ /::/; # OO call return File::Spec->catfile($dir, @_); } sub _find_files { my $type = shift; my $file = shift; shift @$file if ref $$file[0] or $$file[0] =~ /::/; # OO call #warn "Looking for: @$file\n in: @_\n"; if (wantarray) { return grep { &$type( $_ ) && -r $_ } map { File::Spec->catfile($_, @$file) } @_; } else { # prevent unnessecary stats by returning early for (@_) { my $path = File::Spec->catfile($_, @$file); return $path if &$type($path) && -r $path; } } return (); } sub _dir { -d $_[0] } sub _file { -f $_[0] } 1; __END__ =head1 NAME File::BaseDir - Use the Freedesktop.org base directory specification =head1 SYNOPSIS use File::BaseDir qw/xdg_data_files/; for ( xdg_data_files('mime/globs') ) { # do something } =head1 DESCRIPTION This module can be used to find directories and files as specified by the Freedesktop.org Base Directory Specification. This specifications gives a mechanism to locate directories for configuration, application data and cache data. It is suggested that desktop applications for e.g. the Gnome, KDE or Xfce platforms follow this layout. However, the same layout can just as well be used for non-GUI applications. This module forked from L. This module follows version 0.6 of BaseDir specification. =head1 EXPORT None by default, but all methods can be exported on demand. Also the groups ":lookup" and ":vars" are defined. The ":vars" group contains all routines with a "xdg_" prefix; the ":lookup" group contains the routines to locate files and directories. =head1 METHODS =over 4 =item C Simple constructor to allow Object Oriented use of this module. =back =head2 Lookup The following methods are used to lookup files and folders in one of the search paths. =over 4 =item C Takes a list of file path elements and returns a new path by appending them to the data home directory. The new path does not need to exist. Use this when 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 =item C Looks for directories specified by C<@PATH> in the data home and other data directories. Returns (possibly empty) list of readable directories. In scalar context only the first directory found is returned. Use this to lookup application data. =item C Looks for files specified by C<@PATH> in the data home and other data directories. Only returns files that are readable. In scalar context only the first file found is returned. Use this to lookup application data. =item C 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. =item C Looks for directories specified by C<@PATH> in the config home and other config directories. Returns (possibly empty) list of readable directories. In scalar context only the first directory found is returned. Use this to lookup configuration. =item C Looks for files specified by C<@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 lookup configuration. =item C 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. =back =head2 Variables The following methods only returns the value of one of the XDG variables. =over 4 =item C Returns either C<$ENV{XDG_DATA_HOME}> or it's default value. Default is F<$HOME/.local/share>. =item C Returns either C<$ENV{XDG_DATA_DIRS}> or it's default value as list. Default is F, F. =item C Returns either C<$ENV{XDG_CONFIG_HOME}> or it's default value. Default is F<$HOME/.config>. =item C Returns either C<$ENV{XDG_CONFIG_DIRS}> or it's default value as list. Default is F. =item C Returns either C<$ENV{XDG_CACHE_HOME}> or it's default value. Default is F<$HOME/.cache>. =back =head1 NON-UNIX PLATFORMS The use of L ensures that all paths are returned in the apropriate form for the current platform. On Windows this module will try to set C<$HOME> to a sensible value if it is not defined yet. On other platforms one can use e.g. L to set $HOME before loading File::BaseDir. Please note that the specification is targeting Unix platforms only and will only have limited relevance on other platforms. Any platform dependend behavior in this module should be considerd an extension of the spec. =head1 BACKWARDS COMPATIBILITY The methods C and C are exported for backwards compatibilty with version 0.02. They are identical to C and C respectively but without the C behavior. =head1 BUGS Please mail the author if you encounter any bugs. =head1 AUTHOR Jaap Karssenberg || Pardus [Larus] Epardus@cpan.orgE Copyright (c) 2003, 2007 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L libfile-basedir-perl-0.03/configure0000555000175000017500000000004710707721642016311 0ustar jdongjdong#!/bin/sh exec perl ./Makefile.PL "$@" libfile-basedir-perl-0.03/README0000444000175000017500000000124710707721642015265 0ustar jdongjdongFile-BaseDir ============ This module can be used to find directories and files as specified by the Freedekstop.org Base Directory Specification. INSTALLATION To install this module type the following: perl Build.PL ./Build ./Build test ./Build install DEPENDENCIES This module requires these other modules which can be obtained from the CPAN if they are not allready installed on your system : Module::Build Carp Exporter File::Spec COPYRIGHT AND LICENCE Copyright (c) 2003, 2007 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. libfile-basedir-perl-0.03/Build.PL0000444000175000017500000000072410707721642015700 0ustar jdongjdong#!/usr/bin/perl use Module::Build; my $build = Module::Build->new( dist_name => 'File-BaseDir', dist_version_from => 'lib/File/BaseDir.pm', dist_author => 'Jaap Karssenberg ', license => 'perl', requires => { 'Carp' => 0, 'Exporter' => 0, 'File::Spec' => 0, }, build_requires => { 'Module::Build' => '0.24', 'Test::More' => 0, }, create_makefile_pl => 'passthrough', #dynamic_config => 1, ); $build->create_build_script;