Hi monks,
I wonder how hard would it be to create a lexical version of the lib pragma. Illustration:
# @INC is (a,b,c) here { use lib::lexical "d", "e"; # @INC is (d,e,a,b,c) here require Foo; { no lib::lexical "b", "c"; # @INC is (d,e,a) here require Bar; } # @INC is (d,e,a,b,c) here } # @INC is (a,b,c) here
I've read perlpragma and know about %^H, but don't know if it can help in this case. I'm also aware about modules like B::Hooks::EndOfScope, but in this case we want to execute code after the caller's end of scope.
Anyway, there's always this if the above is not possible:
# @INC is (a,b,c) here { local @INC = ("d", "e", @INC); # @INC is (d,e,a,b,c) here require Foo; { local @INC = grep { $_ ne "b" && $_ ne "c" } @INC; # @INC is (d,e,a) here require Bar; } # @INC is (d,e,a,b,c) here } # @INC is (a,b,c) here
In reply to A lexical lib pragma? by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |