use lib::lexical MODULE, PATHSPEC; #### use lib::lexical modules => MODULESPEC, path => PATHSPEC; #### package lib::lexical; our @SAVEINC = @INC; our @LOCALINC = @INC; sub work { my $flag = shift(); my $method = $flag ? 'import' : 'unimport'; my $p = shift; # PACKAGE if (! $p and ! $flag) { # plain 'no lib::lexical;' @LOCALINC = @SAVEINC unless $p; # restore to original @INC return; } if ($flag) { # prepend @paths to @INC unshift @LOCALINC, @_; } else { # weed out @paths from @INC my %i; @i{@_} = (1) x @_; @LOCALINC = grep { ! $i{$_} } @LOCALINC; } local @INC = @LOCALINC; warn $_,$/ for @INC; (my $file = "$p.pm") =~ s!::!/!g; require $file; my $m = $p->can($method); goto &$m if $m; } sub import { shift; unshift @_, 1; goto &work } sub unimport { shift; unshift @_, 0; goto &work } 1; __END__ #### no lib; #### sub unimport { shift; @INC = @ORIG_INC and return unless @_; # patch for the lazy <--- HERE my %names; foreach my $path (@_) { my($arch_auto_dir, $arch_dir, $version_dir, $version_arch_dir) = _get_dirs($path); ++$names{$path}; ++$names{$arch_dir} if -d $arch_auto_dir; ++$names{$version_dir} if -d $version_dir; ++$names{$version_arch_dir} if -d $version_arch_dir; } # Remove ALL instances of each named directory. @INC = grep { !exists $names{$_} } @INC; return; }