* David Cantrell <david.cantr...@uk2group.com> [2015-10-06 17:35]:
> One of my modules is Sub::WrapPackages. It has a feature where you can
> invoke it once and it will both wrap itself around code that's already
> been loaded, but will also lurk in the background and do Things to
> code that is loaded in the future. It does this by dropping sub-refs
> in @INC. It also subverts 'use lib' so that if you 'use lib' after it
> has dropped its magic into @INC, it silently moves its sub-refs to the
> front of @INC.

http://search.cpan.org/search?q=inc
https://metacpan.org/pod/Array::Sticky::INC
https://metacpan.org/pod/Devel::INC::Sorted

Huh.

> The code for this is quite simple and right at the end of Sub::WrapPackages:
> https://metacpan.org/source/DCANTRELL/Sub-WrapPackages-2.0/lib/Sub/WrapPackages.pm#L337

Those other modules both rely on tie’ing @INC, which is more bloated but
also more robust than your solution (they’ll work for code that operates
on @INC directly, unlike your solution). Hmm.

Probably you can use Variable::Magic to write a lower-overhead version.
But then you have to live with the XS requirement. Hmm.

> I now find that I need this functionality in another module, so I'm
> going to rip it out and upload it to the CPAN as a seperate
> distribution that will let you register sub-refs to do this with. But
> what to call that?
>
> Devel::INC::MySubrefsFirst?
>
> I think that sucks, but I can't think of anything better that is still
> reasonably short. Anyone got any better suggestions?

I don’t like the general abuse of Devel:: for things that have nothing
to do with perl’s -d switch (though the abuse was certainly invited by
the reservation of an overly broad TLNS for this purpose).

You’re monkeypatching lib.pm. How about lib::RespectHooks?

That would be particularly descriptive if you avoid the need for any
interface by simplifying the code to something like

    my $newimport = sub {
        my @hook;
        push @hook, shift @INC while ref $INC[0];
        &$originallibimport;
        unshift @INC, @hook;
    };

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to