in reply to Re: How to instrument a "fake" subroutine?
in thread How to instrument a "fake" subroutine?

Because it's just like a normal sub calling itself since the coderef is pointing to the sub that is currently being called.

I don't think I follow. How does it work on non-fake subs then? By your reasoning wouldn't they also recurse? (They don't.)

Unfortunately my actual situation in Devel::Profiler is complicated enough that neither of your solutions will apply directly. But they have given me some good ideas.

Thanks,
-sam

  • Comment on Re: Re: How to instrument a "fake" subroutine?

Replies are listed 'Best First'.
Re: Re: Re: How to instrument a "fake" subroutine?
by broquaint (Abbot) on May 22, 2002 at 21:22 UTC
    I don't think I follow. How does it work on non-fake subs then?
    Hmm, I think we may have our wires crossed (that'll teach me for posting after 10pm ;-) My reasoning is that if your return is the call from a coderef that is pointing to the current coderef then of course it will recurse e.g
    my $f = \&foo; *foo = sub { print "in foo()\n"; return &$f; } foo(); __output__ in foo() in foo() ... and so on
    $f is just pointing to *main::foo{CODE} and since &foo is defined by the time it is called $f will then be pointing to a fully fledged sub and it recurses. Am I missing something?
    HTH

    _________
    broquaint

    update: changed sub foo to *foo = sub {}

      Oh. You were just pointing out the obvious then. I was asking why and you told me what. That's ok. The rest of your post was very helpful.

      -sam