NAME

Aspect::Trace - Modular aspect to trace subroutine calls

SYNOPSIS

use Aspect::Trace;
my $trace = Aspect::Trace->new(qr/^main::(foo|bar)$/);
foo(7);

DESCRIPTION

This class implements a modular aspect that traces subroutine calls.

METHODS

This class inherits from Aspect::Modular. In addition, it implements and/or overrides the following methods:

define(STRING)

Creates and enables advice that implements the tracing behavior for the given subroutines. The specification can be a string, regular expression or a coderef, as described in the PointCut manpage.

spec([spec])

Gets, if called without an argument, or sets, if called with an argument, the aspect's pointcut specification. It is set automatically by define(); setting it afterwards has no effect.

fh([fh])

Gets, if called without an argument, or sets, if called with an argument, the filehandle onto which the trace messages are printed. Unless set, messages are printed to STDOUT and getting the filehandle will return undef. This accessor can be called at any time with an open filehandle; all messages printed afterwards will be directed to the new filehandle.

INTERNALS

This aspect consists of two pieces of advice for each affected subroutine:

  • When calling a subroutine affected by the aspect's pointcut, the subroutine name and arguments are printed along with the context (scalar, array, void).

  • When returning from the subroutine, a message with the subroutine name and return value (or undef if there is none) is printed.

TODO

The constructor could be made to take named arguments specifying formats, along the lines of printf, for the trace messages. Placeholders could include the subroutine name, arguments, context, return value, file name, package name etc.

BUGS

None known so far. If you find any bugs or oddities, please do inform the author.

AUTHOR

Marcel Grunauer, <marcel@codewerk.com>

COPYRIGHT

Copyright 2001 Marcel Grunauer. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), Aspect::Intro(3pm), Aspect::Overview(3pm).