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.
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
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?
--
David Cantrell