NAME

Aspect-Oriented Perl Cookbook - recipes for common situations

DESCRIPTION

This cookbook contains recipes for using aspect-oriented techniques to solve common problems.

Tracing the call flow

Problem

You want to see how subroutines call each other while your program is running.

Solution

Suppose you want to see the call flow for subroutines within the Foo package:

my $adv1 = advice(calls(qr/^Foo::/), sub {
  $::indent++;
  print ' ' x ($::indent - 1), $::thisjp->signature(@_), "\n"
});
my $adv2 = advice(returns(qr/^Foo::/), sub { $::indent-- });

$_->enable for $adv1, $adv2;

Discussion

Create a pointcut designating the call join points of the subroutines you're interested in; then another designating the return join points of those subroutines. Remember the call level by increasing a variable in the call advice, then decreasing it in the return advice. Output the desired information in the call advice.

See Also

The cookbook/01callflow.pl example program.

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

Aspect::Intro(3pm), Aspect(3pm).