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:

package MooselessRequireHookTest; use 5.032; use warnings; sub new { my ($class) = @_; return bless {} => $class; } sub dynamic_require { my ($self, $ns_extension) = @_; { my $class = join '::', __PACKAGE__, $ns_extension; my $source = <<~EOF; package $class; use parent 'MooselessRequireHookTest'; 1; EOF my sub for_inc { my ($coderef, $filename) = @_; return \$source }; my $for_inc_ref = \&for_inc; push @INC, $for_inc_ref; eval "require $class;"; } return; } 1;

sscce_mooseless_require_hook_test.t:

#!perl use 5.032; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Test::More tests => 6; use MooselessRequireHookTest; my $rht = MooselessRequireHookTest::->new(); is(defined $rht, 1, 'Test MooselessRequireHookTest::->new()'); isa_ok($rht, 'MooselessRequireHookTest', 'Test MooselessRequireHookTes +t::->new() ISA'); $rht->dynamic_require('Test1'); my $rht_test1 = MooselessRequireHookTest::Test1->new(); is(defined $rht_test1, 1, 'Test MooselessRequireHookTest::Test1->new() +'); isa_ok($rht_test1, 'MooselessRequireHookTest::Test1', 'Test MooselessR +equireHookTest::Test1->new() ISA'); $rht->dynamic_require('Test2'); my $rht_test2 = MooselessRequireHookTest::Test2->new(); is(defined $rht_test2, 1, 'Test MooselessRequireHookTest::Test2->new() +'); isa_ok($rht_test2, 'MooselessRequireHookTest::Test2', 'Test MooselessR +equireHookTest::Test2->new() ISA');

Example run:

$ prove -v sscce_mooseless_require_hook_test.t sscce_mooseless_require_hook_test.t .. 1..6 ok 1 - Test MooselessRequireHookTest::->new() ok 2 - 'Test MooselessRequireHookTest::->new() ISA' isa 'MooselessRequ +ireHookTest' ok 3 - Test MooselessRequireHookTest::Test1->new() ok 4 - 'Test MooselessRequireHookTest::Test1->new() ISA' isa 'Mooseles +sRequireHookTest::Test1' Can't locate object method "new" via package "MooselessRequireHookTest +::Test2" at sscce_mooseless_require_hook_test.t line 23. # Looks like your test exited with 255 just after 4. Dubious, test returned 255 (wstat 65280, 0xff00) Failed 2/6 subtests Test Summary Report ------------------- sscce_mooseless_require_hook_test.t (Wstat: 65280 Tests: 4 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 6 tests but ran 4. Files=1, Tests=4, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.06 cusr + 0.05 csys = 0.14 CPU) Result: FAIL

— Ken


In reply to Re^4: require() @INC hooks problem [non-Moose] by kcott
in thread require() @INC hooks problem by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.