in reply to Re^2: Monkey patching all subs with a basic 'starting subname' message
in thread Monkey patching all subs with a basic 'starting subname' message

> 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!

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

Replies are listed 'Best First'.
Re^4: Monkey patching all subs with a basic 'starting subname' message
by Anonymous Monk on Jul 17, 2017 at 20:11 UTC

    > 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!

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

      I'm sure there are better ways, for instance I'd try to use closure variables.

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

        I thought the first case was a closure variable. i.e.

        • Closure variable: my $foo = sub { ... };
        • Eval string: my $foo = eval qq{ sub { ... } };

        The thing is, I can only see how I might get the output of prototype into the string and not the closure. i.e.

        • Closure variable:
          my $original_proto = prototype("${package}::${sub_name}"); my $original_sub = \${"${package}::${sub_name}"}; *{"${package}::${sub_name}"} = sub HOW_DO_I_GET_$original_proto_IN_HER +E? { return $original_sub->(@_); };
        • Eval String:
          my $original_proto = prototype("${package}::${sub_name}"); my $original_sub = \${"${package}::${sub_name}"}; *{"${package}::${sub_name}"} = eval qq{sub $original_proto { return \$ +original_sub->(\@_); } };

        Am I missing something obvious?