[Israel.pm] Removing PERLLIB additions to @INC
Yuval Kogman
lists at woobling.org
Tue Jan 13 07:32:55 PST 2004
On Tue, Jan 13, 2004 at 01:48:44PM +0200, David Baird wrote:
> I was updating some old code, and again came across the need to remove
> and additions made to @INC by PERLLIB. Recall a suggestion by Gabor:
>
> > BEGIN {
> > if (defined $ENV{PERLLIB}) {
> > foreach my $path (split /;/, $ENV{PERLLIB}) {
> > @INC = grep {lc $path ne lc $_} @INC;
> > }
> > }
> > }
> Good enough. But I also thought of another solution, which works on
> any OS platform.
Cross platform compatibility could be made by porting Env::Path, or
assuming it's ported, and using it instead.
File::Spec::Functions::case_tolerant should be used to take care of
the lc part, if at all - the PERL5?LIB variables shouldn't be munged
before going into @INC, AFAIK.
This will be weirder on darwin, for example, where the same file
system (HFS+) can be case sensitive, or insensitive. I don't think
such cases should even be tested for.
> In a situation where I don't want additions made by the end user
> through PERLLIB, this seems to be the most straight forward
> approach.
Well, additions from the user will still happen.
> I need to make sure that my script only loads modules from my
> specialized Perl installation.
If something else /will/ break, Gabor's solution is more sane. If you
would just like percedence for the core modules, yours would do it.
Gabor's solution has one disadvantage - things that are supposedly
cross platform, and which the user wants added, will not be available,
and will cause a lot of headache.
> Thoughts?
Indeed:
#!/usr/bin/perl
no env qw/PERLLIB/; # or PATH, or all... whatever.
use strict;
use warnings;
use Socket;
__END__
Could be useful if made complete, and suprise - it's not on CPAN
yet. =)
Ofcourse, it will only work so far, not modifying perl's runtime
itself, but it still might be useful for these kinds of situations.
Any takers?
--
() Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: /me has realultimatepower.net: neeyah!!!!!!!!!!!!
More information about the Perl
mailing list