in reply to Re^2: require() @INC hooks problem
in thread require() @INC hooks problem
(Moose doesn't qualify as "short" or "self contained" in my book ;-)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: require() @INC hooks problem [non-Moose]
by kcott (Archbishop) on Dec 27, 2020 at 21:52 UTC | |
Out of curiousity, I took Moose out of the equation. There was no change to the problem; however, if you or someone else can solve the non-Moose issue, I suspect that solution can probably be applied to the Moose version. I've made no changes to the module structure: just added a new() routine; changed extends to use parent; and so on. Everything is pretty much the same except all classes are now prefixed with Mooseless. MooselessRequireHookTest.pm:
sscce_mooseless_require_hook_test.t:
Example run:
— Ken | [reply] [d/l] [select] |
by choroba (Cardinal) on Dec 27, 2020 at 22:24 UTC | |
Cleaner way is to check the name in the hook itself, e.g. before returning \$source, insert
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |
by kcott (Archbishop) on Dec 28, 2020 at 00:30 UTC | |
G'day choroba, ++ Many thanks for this. The namespace extension ($ns_extension) can contain several parts, e.g. A::B::C, so I made a slight adjustment to handle that. I also pared the code, bit by bit, to end up with the simplified:
I added a couple more tests:
I also added this temporary debug line after unpacking @_:
Now, all tests are successful and I have a little more insight into what is going on:
The mechanism behind this is a mystery to me. Why is it calling the subroutine with all the previous CODEREF values then the newly created CODEREF? Anyway, what you provided weeds out all of the unwanted parts. @INC ends up with: the use lib dir; the 4 usual dirs; and 3 (hook) CODEREFs.
As I suspected, the issue had nothing to do with Moose. I applied these changes to my original module and all of its tests now pass. Thanks again. — Ken | [reply] [d/l] [select] |
Re^4: require() @INC hooks problem
by kcott (Archbishop) on Dec 27, 2020 at 21:18 UTC | |
OK, that's fine. Thanks for taking the time to make some guesses. — Ken | [reply] |
by LanX (Saint) on Dec 27, 2020 at 21:28 UTC | |
I'm very interested in hooks, but Moose is an obstacle I'm trying to evade like a Mercedes. ;-)
Cheers Rolf | [reply] |