http://www.perlmonks.org?node_id=11107611


in reply to Re: [implementation specific to windows] writing a proper batch file for terminal start-up
in thread [implementation specific to windows] writing a proper batch file for terminal start-up

If you have your code set up as a standard directory structure, e.g. with the script in ./bin and any modules under ./lib, then you can use libraries like rlib to add the relative paths in your calling script.

Ok, this is helpful and worth exploring. I must say, however, that I'm unable to follow what rlib is doing. Let's look at the source:

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__

I fail to see how _dirs is populated. Can someone talk through how this works? In particular, I do not understand the syntax of the following lines:

my($pkg,$file) = (caller(1))[0,1]; my @rel = @_ ? @_ : qw(../lib lib);

and

while($pkg =~ /::/g) {

How might I test this? Thx for your comments,