diff --git a/lib/Find/Lib.pm b/lib/Find/Lib.pm index bea66bf..cd05ba5 100644 --- a/lib/Find/Lib.pm +++ b/lib/Find/Lib.pm @@ -3,7 +3,7 @@ use strict; use warnings; use lib; -use File::Spec::Functions qw( catpath splitpath rel2abs catdir splitdir ); +use File::Spec::Functions qw( catpath splitpath rel2abs splitdir ); use vars qw/$Base $VERSION @base/; use vars qw/$Script/; # compat @@ -138,7 +138,7 @@ sub guess_shell_path { ## a clean base is also important for the pop business below #@base = grep { $_ && $_ ne '.' } shell_resolve(\@base, \@zero); @base = shell_resolve(\@base, \@zero); - return catpath( $volume, (catdir @base), '' ); + return catpath( $volume, (File::Spec->catdir( @base )), '' ); } ## naive method, but really DWIM from a developer perspective @@ -184,24 +184,47 @@ sub import { lib->import($_); next; } - my $dir = catdir( shell_resolve( [ @base ], \@lib ) ); + my $dir = File::Spec->catdir( shell_resolve( [ @base ], \@lib ) ); unless (-d $dir) { ## Try the old way (<0.03) - $dir = catdir($Base, $_); + $dir = File::Spec->catdir($Base, $_); } next unless -d $dir; lib->import( $dir ); } } +=head2 base + +Returns the detected base (the directory where the script lives in). It's a +string, and is the same as C<$Find::Lib::Base>. + +=cut + +sub base { return $Base } + =head2 catfile A shorcut to L using B's base. +=cut + +sub catfile { + my $class = shift; + return File::Spec->catfile($Base, @_); +} + =head2 catdir A shorcut to L using B's base. +=cut + +sub catdir { + my $class = shift; + return File::Spec->catdir($Base, @_); +} + =head1 BACKWARD COMPATIBILITY in versions <1.0 of Find::Lib, the import arguments allowed you to specify diff --git a/t/01-basic.t b/t/01-basic.t index 83be694..ecfe7f3 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -3,7 +3,7 @@ use Test::More tests => 8; require 't/testutils.pl'; -use File::Spec qw(catfile catdir); +use File::Spec; use Find::Lib 'mylib'; use_ok 'MyLib'; @@ -13,6 +13,6 @@ my $base = Find::Lib->base; ok $base, 'base() returns the directory of your script'; is $base, $Find::Lib::Base, "It's accessible from outside"; -is Find::Lib->catfile('something'), catfile($base, 'something'); -is Find::Lib->catdir('dir'), catdir($base, 'dir'); -is Find::Lib->catdir('..', 'dir'), catdir($base, '..', 'dir'); +is (Find::Lib->catfile('something'), File::Spec->catfile($base, 'something')); +is (Find::Lib->catdir('dir'), File::Spec->catdir($base, 'dir')); +is (Find::Lib->catdir('..', 'dir'), File::Spec->catdir($base, '..', 'dir'));