| rlib documentation | Contained in the rlib distribution. |
rlib - manipulate @INC at compile time with relative paths
use rlib LIST;
no rlib LIST;
rlib works in the same way as lib, except that all paths in LIST
are treated as relative paths.
If rlib is used from the main package then the paths in LIST
are assumed to be relative to where the current script $0 is
located. This is done by using the FindBin package.
If rlib is used from within any package other tha main then the
paths in LIST are assumed to be relative to the root of the library
where the file for that package was found.
If LIST is empty then "../lib","lib" is assumed.
lib - module which adds paths to @INC
FindBin - module for locating script bin directory
Graham Barr <gbarr@pobox.com>
| rlib documentation | Contained in the rlib distribution. |
package rlib; use strict; use vars qw($VERSION @ISA); use lib (); use File::Basename qw(dirname); use File::Spec; $VERSION = "0.02"; @ISA = qw(lib); sub _dirs { my($pkg,$file) = (caller(1))[0,1]; my @rel = @_ ? @_ : qw(../lib lib); my $dir; # if called from package main then assume we were called # by a script not a module if($pkg eq 'main') { require FindBin; # hide "used only once" warning $dir = ($FindBin::Bin,$FindBin::Bin)[0]; } else { require Cwd; $dir = Cwd::abs_path(dirname($file)); } # If we were called by a package then traverse upwards # to root of lib while($pkg =~ /::/g) { $dir = dirname($dir); } if($^O eq 'VMS') { require VMS::Filespec; @rel = map { VMS::Filespec::unixify($_) } @rel; } map { File::Spec->catdir($dir,$_) } @rel; } sub import { shift->SUPER::import( _dirs(@_) ); } sub unimport { shift->SUPER::unimport( _dirs(@_) ); } 1; __END__