in reply to Monkey patching all subs with a basic 'starting subname' message

If I were you I'd check CPAN for related modules, maybe looking for "advice" (a LISP term) or "around" or "before/after"

> Any other wisdom to be shared here (bar the obvious "don't" and "use a cpan module")?

Well even if you do it yourself, you are free to look into the code

concerning:

1. You can check the target prototype before patching with prototype

3. It's possible to inspect the originating "home" package of a sub, again try searching the archives here°

Nota bene: Perl has a trace option ( perlrun ) and the debugger has many means to "watch" subs ( perldebug )

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

°) See B::svref_2object($subref) in B

  • Comment on Re: Monkey patching all subs with a basic 'starting subname' message

Replies are listed 'Best First'.
Re^2: Monkey patching all subs with a basic 'starting subname' message
by Anonymous Monk on Jul 14, 2017 at 19:53 UTC

    Thanks, Rolf;

    'Advice' and 'around' are indeed very good search keywords for examples of what I am doing, and point me right to people who I am sure have done it well -- thanks for this.

    prototype is -- now that I have seen it -- obvious, really! Can't believe I missed that on my first scan through perlfunc! I have managed to fold the output of this into my code using eval; of course, now the meat of my redefined sub is essentially a string -- is this the sanest way to apply this?

      > of course, now the meat of my redefined sub is essentially a string -- is this the sanest way to apply this?

      Not sure what this "meat" is supposed to mean (?)

      Could you show some code?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        > Not sure what this "meat" is supposed to mean (?)

        In this case, meat == "majority". As in, what was...

        *$_ = sub { __dbg { "Starting ${package}::${fname}(", join(',', @_), ')' } 4; my @ret = $fn->(@_); };

        ...now becomes...

        *$_ = eval qq{sub $proto { __dbg { "Starting ${package}::${fname}(", join(',', \@_), ')' } 4; my \@ret = \$fn->(\@_); }};

        The eval of an escaped+interpolated string is now just as worrying as the other stuff I was worried about!

        All of which, I'm sure, is the least of my worries!