Jaap Karssenberg wrote:
Show quoted text> I have no strong feelings about these prefixes one way or the other, but
> if I drop them now this will break all applications using them at the
> moment. Of course I can make both available and only document without
> prefix, but I'm not completely convinced it is worth the trouble.
>
> Personally I really like the prefix functionality of Exporter::Tidy, but
> I'm reluctant to add this module as a dependency for common CPAN modules
> like File::BaseDir.
Yeah, just alias them and forget the xdg_ versions ever existed. It's a
simple patch, no additional modules required.
I've attached two patches, meant to be applied consecutively. The first
strips out all the xdg prefixes. The second puts in aliases and documents the
change. I hadn't realized File::BaseDir was 4 years old, thought it was
something brand new because of the 0.02 file version.
Show quoted text> I'm probably releasing a small update for this module in the next few
> weeks. Maybe I can make the documentation a bit more verbose to make it
> more clear what the use of this module is?
I prefer fixing the root problem rather than patching over it. In my case, I
just saw a sample of the code mentioned on a mailing list.
http://www.nntp.perl.org/group/perl.qa/2007/10/msg9459.html
Show quoted text> Hope to see you again next time in Portland.
I'll be here. :)
--
Don't try the paranormal until you know what's normal.
-- "Lords and Ladies" by Terry Prachett
----------------------------------------------------------------------
r40731: schwern | 2007-10-21 17:32:16 -0400
Remove all the xdg_* prefixes.
----------------------------------------------------------------------
--- local/File-BaseDir/t/1.t (revision 40730)
+++ local/File-BaseDir/t/1.t (revision 40731)
@@ -1,15 +1,15 @@
use Test::More tests => 5;
-use_ok('File::BaseDir', qw/xdg_data_home xdg_data_dirs xdg_data_files/); # 1
+use_ok('File::BaseDir', qw/data_home data_dirs data_files/); # 1
ok( ref(File::BaseDir->new) eq 'File::BaseDir', 'OO constructor works'); # 2
$ENV{XDG_DATA_HOME} = 'test123';
-ok( xdg_data_home() eq 'test123', 'xdg_data_home works'); # 3
+ok( data_home() eq 'test123', 'data_home works'); # 3
$ENV{XDG_DATA_DIRS} = './t/';
-ok( -d ( xdg_data_dirs() )[0], 'xdg_data_dirs work'); # 4
+ok( -d ( data_dirs() )[0], 'data_dirs work'); # 4
-my $file = ( xdg_data_files('some_file') )[0];
-ok( -e $file, 'xdg_data_files seems to work'); # 5
+my $file = ( data_files('some_file') )[0];
+ok( -e $file, 'data_files seems to work'); # 5
--- local/File-BaseDir/BaseDir.pm (revision 40730)
+++ local/File-BaseDir/BaseDir.pm (revision 40731)
@@ -7,50 +7,50 @@
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
- xdg_data_home xdg_data_dirs xdg_data_files
- xdg_config_home xdg_config_dirs xdg_config_files
- xdg_cache_home
+ data_home data_dirs data_files
+ config_home config_dirs config_files
+ cache_home
);
our $VERSION = 0.02;
my $rootdir = File::Spec->rootdir();
-our $xdg_data_home = File::Spec->catdir($ENV{HOME}, qw/.local share/);
-our @xdg_data_dirs = (
+our $data_home = File::Spec->catdir($ENV{HOME}, qw/.local share/);
+our @data_dirs = (
File::Spec->catdir($rootdir, qw/usr local share/),
File::Spec->catdir($rootdir, qw/usr share/),
);
-our $xdg_config_home = File::Spec->catdir($ENV{HOME}, '.config');
-our @xdg_config_dirs = ( File::Spec->catdir($rootdir, qw/etc xdg/) );
+our $config_home = File::Spec->catdir($ENV{HOME}, '.config');
+our @config_dirs = ( File::Spec->catdir($rootdir, qw/etc xdg/) );
-our $xdg_cache_home = File::Spec->catdir($ENV{HOME}, '.cache');
+our $cache_home = File::Spec->catdir($ENV{HOME}, '.cache');
sub new { bless \$VERSION, shift } # what else is there to bless ?
-sub xdg_data_home { $ENV{XDG_DATA_HOME} || $xdg_data_home }
+sub data_home { $ENV{XDG_DATA_HOME} || $data_home }
-sub xdg_data_dirs {
+sub data_dirs {
( $ENV{XDG_DATA_DIRS}
? _adapt($ENV{XDG_DATA_DIRS})
- : @xdg_data_dirs
+ : @data_dirs
)
}
-sub xdg_data_files { _find_files(\@_, xdg_data_home, xdg_data_dirs) }
+sub data_files { _find_files(\@_, data_home, data_dirs) }
-sub xdg_config_home {$ENV{XDG_CONFIG_HOME} || $xdg_config_home }
+sub config_home {$ENV{XDG_CONFIG_HOME} || $config_home }
-sub xdg_config_dirs {
+sub config_dirs {
( $ENV{XDG_CONFIG_DIRS}
? _adapt($ENV{XDG_CONFIG_DIRS})
- : @xdg_config_dirs
+ : @config_dirs
)
}
-sub xdg_config_files { _find_files(\@_, xdg_config_home, xdg_config_dirs) }
+sub config_files { _find_files(\@_, config_home, config_dirs) }
-sub xdg_cache_home { $ENV{XDG_CACHE_HOME} || $xdg_cache_home }
+sub cache_home { $ENV{XDG_CACHE_HOME} || $cache_home }
sub _adapt {
map { File::Spec->catdir( split('/', $_) ) }
@@ -75,8 +75,8 @@
=head1 SYNOPSIS
- use File::BaseDir qw/xdg_data_files/;
- for ( xdg_data_files('mime/globs') ) {
+ use File::BaseDir qw/data_files/;
+ for ( data_files('mime/globs') ) {
# do something
}
@@ -102,37 +102,37 @@
Simple constructor to allow Object Oriented use of this module.
-=item C<xdg_data_home>
+=item C<data_home>
Returns either C<$ENV{XDG_DATA_HOME}> or it's default value.
-=item C<xdg_data_dirs>
+=item C<data_dirs>
Returns either C<$ENV{XDG_DATA_DIRS}> or it's default value.
-=item C<xdg_data_files($file)>
+=item C<data_files($file)>
Searches for C<$file> in all C<XDG_DATA_DIRS> and only returns
existing readable files.
The file path can also be given as a list.
-=item C<xdg_config_home>
+=item C<config_home>
Returns either C<$ENV{XDG_CONFIG_HOME}> or it's default value.
-=item C<xdg_config_dirs>
+=item C<config_dirs>
Returns either C<$ENV{XDG_CONFIG_DIRS}> or it's default value.
-=item C<xdg_config_files($file)>
+=item C<config_files($file)>
Searches for C<$file> in all C<XDG_CONFIG_DIRS> and only returns
existing readable files.
The file path can also be given as a list.
-=item C<xdg_cache_home>
+=item C<cache_home>
Returns either C<$ENV{XDG_CACHE_HOME}> or it's default value.
----------------------------------------------------------------------
r40732: schwern | 2007-10-21 17:45:51 -0400
Alias all the exported functions to their xdg_ equivalents. Put in a test
for them and mention the change in the docs.
----------------------------------------------------------------------
--- local/File-BaseDir/t/backwards.t (revision 40731)
+++ local/File-BaseDir/t/backwards.t (revision 40732)
@@ -1,15 +1,15 @@
use Test::More tests => 5;
-use_ok('File::BaseDir', qw/data_home data_dirs data_files/); # 1
+use_ok('File::BaseDir', qw/xdg_data_home xdg_data_dirs xdg_data_files/); # 1
ok( ref(File::BaseDir->new) eq 'File::BaseDir', 'OO constructor works'); # 2
$ENV{XDG_DATA_HOME} = 'test123';
-ok( data_home() eq 'test123', 'data_home works'); # 3
+ok( xdg_data_home() eq 'test123', 'xdg_data_home works'); # 3
$ENV{XDG_DATA_DIRS} = './t/';
-ok( -d ( data_dirs() )[0], 'data_dirs work'); # 4
+ok( -d ( xdg_data_dirs() )[0], 'xdg_data_dirs work'); # 4
-my $file = ( data_files('some_file') )[0];
-ok( -e $file, 'data_files seems to work'); # 5
+my $file = ( xdg_data_files('some_file') )[0];
+ok( -e $file, 'xdg_data_files seems to work'); # 5
--- local/File-BaseDir/BaseDir.pm (revision 40731)
+++ local/File-BaseDir/BaseDir.pm (revision 40732)
@@ -5,14 +5,26 @@
require File::Spec;
require Exporter;
-our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(
+# These used to be prefixed with xdg_. Make aliases to
+# them for backwards compatibility.
+my @were_xdg_functions = qw(
data_home data_dirs data_files
config_home config_dirs config_files
cache_home
);
+my @xdg_functions = map { "xdg_$_" } @were_xdg_functions;
+
+for my $function (@were_xdg_functions) {
+ no strict 'refs';
+ *{'xdg_' . $function} = \&{$function};
+}
+
+our @ISA = qw(Exporter);
+our @EXPORT_OK = (@were_xdg_functions, @xdg_functions);
+
our $VERSION = 0.02;
+
my $rootdir = File::Spec->rootdir();
our $data_home = File::Spec->catdir($ENV{HOME}, qw/.local share/);
@@ -138,6 +150,15 @@
=back
+=head1 BACKWARDS COMPATIBILITY
+
+=head2 xdg prefix
+
+Before version 0.03 each function was prefixed with C<xdg_>.
+C<config_home> was C<xdg_config_home>, for example. At 0.03 these
+prefixes were dropped. The functions still exist for backwards
+compatibility purposes.
+
=head1 BUGS
Please mail the author if you encounter any bugs.
@@ -146,7 +167,7 @@
Jaap Karssenberg || Pardus [Larus] E<lt>pardus@cpan.orgE<gt>
-Copyright (c) 2003 Jaap G Karssenberg. All rights reserved.
+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.
--- local/File-BaseDir/MANIFEST (revision 40731)
+++ local/File-BaseDir/MANIFEST (revision 40732)
@@ -1,8 +1,9 @@
-configure
BaseDir.pm
Changes
+configure
Makefile.PL
MANIFEST
README
t/1.t
+t/backwards.t
t/some_file