Aspect::Advice - change how Perl code is run at a pointcut
# 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::/ );
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.
before
after
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.
use()
before()
after()
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.
weaver()
type()
code()
pointcut()
See the Aspect pod for a guide to the Aspect module.
To install Aspect, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Aspect
CPAN shell
perl -MCPAN -e shell install Aspect
For more information on module installation, please visit the detailed CPAN module installation guide.