in reply to Convenient way to track function calls?

AUTOLOAD is nice for this kind of thing.
  • Comment on Re: Convenient way to track function calls?

Replies are listed 'Best First'.
Re: Re: Convenient way to track function calls?
by lestrrat (Deacon) on Aug 29, 2001 at 22:59 UTC

    I'm not exactly sure what the original poster wants, but I believe he already has a module full of subs. AUTOLOAD only gets called when a particular sub doesn't exist in that namespace, correct?

    But I think it's a good idea -- if you can impose a wrapper over the orignal module, you can track all subsequent calls:

    package Foo; sub foo1 { ... } sub foo2 { ... } # etc 1; package Wrapper; use Foo; use vars qw/ $AUTOLOAD /; sub AUTOLOAD { my $subname = $AUTOLOAD; $subname =~ s/.*:://; if( UNIVERSAL::can( 'Foo', $subname ) ) { print LOG "Foo::$subname called\n"; return eval "Foo::$subname( \@_ )"; } else { croak "No such sub: $AUTOLOAD"; } }

    This way you can keep track of exactly every subroutine call in Foo. Is that what you are saying?

      That's exactly what I was suggesting. I was in a bit of a rush and you noticed the figurative handwaving as I went out the door. Nice job of interpretation. :)

      You might want a wantarray thrown in there somewhere to handle function calls in different contexts, if that's important.

      The other suggestion I have is use the Devel::Prof module and simply cook the output from the dprofpp. I think that assumes you have a Perl built for debugging though.