perlancar has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A lexical lib pragma?
by ikegami (Patriarch) on Jan 04, 2020 at 06:01 UTC | |
by perlancar (Hermit) on Jan 04, 2020 at 08:01 UTC | |
by ikegami (Patriarch) on Jan 04, 2020 at 08:28 UTC | |
|
Re: A lexical lib pragma?
by LanX (Saint) on Jan 04, 2020 at 04:49 UTC | |
by perlancar (Hermit) on Jan 04, 2020 at 04:57 UTC | |
by haukex (Archbishop) on Jan 04, 2020 at 09:03 UTC | |
by perlancar (Hermit) on Jan 04, 2020 at 10:12 UTC | |
by haukex (Archbishop) on Jan 04, 2020 at 21:47 UTC | |
by Anonymous Monk on Jan 04, 2020 at 05:16 UTC | |
|
Re: A lexical lib pragma?
by shmem (Chancellor) on Jan 04, 2020 at 16:54 UTC | |
by perlancar (Hermit) on Jan 05, 2020 at 05:10 UTC |