[sf-perl] use lib: order doesn't seem to matter
Randy J. Ray
rjray at blackperl.com
Tue Aug 24 11:40:38 PDT 2010
Michael Friedman wrote:
> I managed a work around for this behavior at my office a while ago. We have each developer set an environment variable containing their personal module path and use that in preference to the default. It requires this at the top of each script, though:
>
> BEGIN {
> if ( $ENV{PERL_LIB} =~ /\:/ ) {
> unshift( @INC, split( /\:/, $ENV{PERL_LIB} ) );
> }
> elsif ( $ENV{PERL_LIB} ) {
> unshift( @INC, $ENV{PERL_LIB} );
> }
> else {
> unshift( @INC, '/path/to/production/lib/perl5' );
> }
> }
>
>
> The colon splitting was added when we realized we wanted to split our perl modules into multiple CVS projects. They're all in one production directory, but in individual project directories for each developer.
Not meaning to venture into golf territory, but the elsif is unnecessary:
BEGIN {
if ( $ENV{PERL_LIB} ) {
unshift( @INC, split( /\:/, $ENV{PERL_LIB} ) );
}
else {
unshift( @INC, '/path/to/production/lib/perl5' );
}
}
split() will do what you want (return a single-item list) when there is content
in PERL_LIB but no ":".
As to why you'd do this instead of PERL5LIB, PERL5LIB is added to @INC before
any "use lib" are processed. This block can be placed in a way such that you
control the timing of when the path-elements are added. Different solutions for
different folks/problems, and all that...
Randy
--
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray Sunnyvale, CA http://www.rjray.org rjray at blackperl.com
Silicon Valley Scale Modelers: http://www.svsm.org
More information about the SanFrancisco-pm
mailing list