Created
June 4, 2009 04:36
-
-
Save kentfredric/123437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lib::relative; | |
# $Id:$ | |
use strict; | |
use warnings; | |
use parent 'lib'; | |
sub to { | |
my $self = shift; | |
my $path = shift; | |
my $from = shift; | |
my @caller = caller; | |
$from ||= $caller[1]; | |
require File::Spec; | |
require File::Basename; | |
return File::Spec->rel2abs( $path, | |
File::Spec->rel2abs( File::Basename::dirname($from) ) ); | |
} | |
sub import { | |
my $self = shift; | |
my $path = shift; | |
my @caller = caller; | |
my $expand = $self->to( $path, $caller[1] ); | |
unshift @_, $expand; | |
unshift @_, $self; | |
goto \&lib::import; | |
} | |
1; | |
__END__ | |
Sick of doing this in your code ? | |
use FindBin; | |
use lib "$FindBin::Bin/../path/to/lib/dir"; | |
? | |
Try this: | |
use lib::relative "../path/to/lib/dir" ; | |
Itch->scratch(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment