Ran Eilam > Aspect-0.12 > Aspect::Advice

Download:
Aspect-0.12.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  1
View/Report Bugs
Module Version: 0.10   Source   Latest Release: Aspect-1.04

NAME ^

Aspect::Advice - change how Perl code is run at a pointcut

SYNOPSIS ^

  # creating using public interface: trace calls to Account subs
  use Aspect;
  before { print 'called: '. shift->sub_name } call qw/^Account::/;

  # creating using internal interface
  use Aspect::Advice;
  $advice = Aspect::Advice->new(before =>
     { print 'called: '. shift->sub_name },
     call qw/^Account::/
  );

DESCRIPTION ^

An advice is composed of a pointcut and some code that will run at the pointcut. The code is run before or after the pointcut, depending on advice type.

You do not normally create advice using the constructor. By use()ing Aspect, you get 2 subs imported: before() and after(), that do what you need. They also store the advice if called in void context, so you do not need to keep in scope. The advice code will be removed when the advice object is destroyed.

The advice code is given one parameter: an Aspect::AdviceContext. You use this object to change the parameter list for the matched sub, modify return value, find out information about the matched sub, and more.

This class has no public methods that do anything, but there are accessors weaver(), type(), code(), and pointcut(), if you need them.

SEE ALSO ^

See the Aspect pod for a guide to the Aspect module.

syntax highlighting: