FAQ
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

Search Discussions

  • Aristotle Pagaltzis at Oct 6, 2015 at 4:19 pm

    * David Cantrell [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/>
  • John M Gamble at Oct 6, 2015 at 4:21 pm
    My first thought was to question whether INC needed to be a whole level
    in the
    name, but... upon consideration, yes, because it's the main point of the
    module.
    Plus, there's precedence in Devel-INC-Sorted.

    So my next thought is the third-level name. I'd drop the "My" and the
    "First"
    and just call it Devel-INC-Subrefs. Justification for dropping "My"
    being, well,
    whose else modules would you be wrapping; and justification for dropping
    "First"
    is that I could very well see an option for putting them in other
    positions as a
    possibility (e.g., after=>"Games::*"), so why limit yourself?

          -john
    On 10/6/2015 10:29 AM, David Cantrell wrote:
    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?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmodule-authors @
categoriesperl
postedOct 6, '15 at 3:30p
activeOct 6, '15 at 4:21p
posts3
users3
websitecpan.org...

People

Translate

site design / logo © 2021 Grokbase