in reply to Re: How is redefining a sub internally done?
in thread How is redefining a sub internally done?

> Does B::Concise distinguish between these

Yes, for instance if a sub is not predefined in the STASH you'll see the *main::g or rather *g form.

Also in (for me) random cases where it's predefined.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Update
~/perl $ perl -MO=Concise,-exec -e'g();' 1 <0> enter v 2 <;> nextstate(main 1 -e:1) v:{ 3 <0> pushmark s 4 <#> gv[*g] s/EARLYCV 5 <1> entersub[t2] vKS/TARG 6 <@> leave[1 ref] vKP/REFC -e syntax OK ~/perl $

s/EARLYCV means the sub was unknown at compile time.

Replies are listed 'Best First'.
Re^3: How is redefining a sub internally done?
by ikegami (Patriarch) on Sep 29, 2024 at 16:31 UTC

    Inherited subs are cached into the namespace that inherits them.

    # Causes something akin to # `*Foo::method = \&Base::method;` $foo->method();

    But it uses a counter system to invalidate the cache. The package's counter is incremented when the package is changed, making it so the counter in the cached entry no longer matches the package's, invalidating the cached entry.

    Perhaps that same mechanism is used here.

      Well maybe

      I tried to look into the code of pp_entersub but didn't understand much... 🤷🏻‍♂️

      Personally when trying to implement this, I would try to use the original sub to link to the current one. Hence just a hop away.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery