你没有那个,但你可以自己做。
package libr;
use strict;
use warnings;
use File::Spec;
sub import {
shift; # invoker
my ( @cands, @missed );
ARGS:
while ( @_ ) {
# Get the next argument from the queued candidates or from the
# arguments
my $raw_path
= my $path
= @cands ? shift @cands : shift
;
# We don't need to worry about this argument unless it has relative
# notation in it.
if ( index( $path, '::' ) > -1 ) {
# split it into parts
my ( $mod, $rest ) = split qr{(?:/(?:\.(?=/))?)+}, $path, 2;
$mod =~ s/^:://; # Allow for one-word relative nodes: 'Word::/';
# Move it from mod notation to file...
my ( $mod_path ) = map { s|::|/|g; $_ } $mod;
my %set;
while ( my $len = length $mod_path ) {
# Remember the more specific path first
$set{ $_ } ||= $mod_path
foreach
# for each key that qualifies, subtract the same
# number of characters from the end of the value
map { substr( $INC{ $_ }, 0, $len - length ) . $rest }
# test each key that it starts with our string
grep { substr( $_, 0, $len ) eq $mod_path }
keys %INC
;
}
continue {
# Check if our separator is in the mod path.
my $mark = rindex( $mod_path, '/' );
last if $mark == -1;
# move the unmatched part of the substring to the
# ending
substr( $rest, 0, 0, substr( $mod_path, $mark ));
# delete it from the path
substr( $mod_path, $mark ) = '';
}
my @sort_order
# We only want the first value...
= map { shift @$_ }
# sort by length of matching path first, then alphabetically
sort { $b->[2] <=> $a->[2] or $a->[1] cmp $b->[1] }
# store a collection of values for sorting:
# lowercase string and length of matching string
map { [ $_ => lc $_ => length $set{ $_ } ] }
keys %set
;
### Assemble list of candidates
@cands = ( @sort_order, map { "$_/$mod_path$rest" } @INC );
next ARGS;
}
# If the path exists
if ( -e $path ) {
# Store the canonical path
push @INC, File::Spec->canonpath( $path );
# And reset tracking arrays
@cands = () if @cands;
@missed = () if @missed;
}
elsif ( @cands ) {
# If we're trying out values, just remember the missed ones.
push @missed, $path;
}
else {
# Else, we're going to tell you we couldn't match the directory
# either to one or to all candidates we tried.
Carp::carp(
"A valid path cannot be determined from '$raw_path': "
. ( @missed > 1 ? do {
local $LIST_SEPARATOR = "\n - ";
push @missed, '', $path;
"\n No paths:@missed\n do not exist!";
}
: "$path does not exist!"
));
@missed = () if @missed;
} # end else
} # end while @_
}
然后你像这样使用:
package main;
use A::Long::Package::Name;
use Smart::Comments;
use libr 'A::Long::Package::Name/../Foo', 'Figgy::Puddin';
试着在说完@INC
话后转出,看看发生了什么。