The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Devel::TraceMethods - Perl module for tracing module calls

SYNOPSIS

  use Devel::TraceMethods qw ( PackageOne PackageTwo );

DESCRIPTION

Devel::TraceMethods allows you to attach a subroutine of your choosing to all of the methods and functions within multiple packages or classes. You can use this to trace execution. It even respects inheritance.

To enable logging, simply pass the name of the packages you wish to trace on the line where you use Devel::TraceMethods. It will automatically install logging for all functions in the named packages.

You can also call import() after you have use()d the module if you want to log functions and methods in another package.

By default, Devel::TraceMethods will use Carp::carp() to log a method call. You can change this with the callback() function. Simply pass a subroutine reference as the only argument, and all subsequent calls to logged methods will use the new subroutine reference instead of carp().

The first argument to the logging subroutine is the name of the logged method. (I wish that sentence were clearer.) The rest of the arguments are those being passed to the logged method. If you really really need to modify them, you can. If you do and it breaks your program, try to be more careful next time. You should probably just print or ignore them.

TODO

Attach to calling package if nothing is specified in @_? Something like:
        push @_, scalar caller() unless @_;
Attach only to specified methods.
Add ability to disable logging on certain methods.
Allow multiple logging subs.
Allow per-method logging sub?
Don't copy other slots of typeglob? (Could be tricky, an internals wizard will have to look at this.)

AUTHOR

 13 June 2001
 chromatic, chromatic@wgz.org

based on a suggestion by tye at PerlMonks, enhanced with a callback suggestion by grinder at PerlMonks.

SEE ALSO

perl(1).