Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: A lexical lib pragma?by shmem (Chancellor) |
on Jan 04, 2020 at 16:54 UTC ( [id://11110949]=note: print w/replies, xml ) | Need Help?? |
I wonder how hard would it be to create a lexical version of the lib pragma. Short answer: very hard, since restoring @INC from a lexical must be done at compile time. But without a BEGIN block, this lexical is set at runtime. So Padwalker maybe, or some wizardry which works on the code which is currently being compiled - if such a beast exists at all. I would go the route of the if module:
or even
without modifying @INC at all in the calling code, and leave that to the module loader lib::lexical, which localizes @INC. So, for the first usage, something like this:
Wait, what - this is (roughly) just what the lib module does? Yes of course! But I'd like to have
just restore the original @INC, so lib::unimport should be:
And then, the lib module modifies @INC globally, whereas the above module just uses a modified @INC for one use call (and the use calls which this call triggers)/.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|