Skip to content

Commit

Permalink
The rest of the new utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yannk committed Oct 22, 2009
1 parent 80ac0c0 commit 4629a37
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
31 changes: 27 additions & 4 deletions lib/Find/Lib.pm
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<File::Spec::catfile> using B<Find::Lib>'s base.
=cut

sub catfile {
my $class = shift;
return File::Spec->catfile($Base, @_);
}

=head2 catdir
A shorcut to L<File::Spec::catdir> using B<Find::Lib>'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
Expand Down
8 changes: 4 additions & 4 deletions t/01-basic.t
Expand Up @@ -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';

Expand All @@ -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'));

0 comments on commit 4629a37

Please sign in to comment.