Change how perl code is run at a pointcut
# Trace calls to all functions in all MyAccount classes use Aspect; before { print 'Called: '. $_->sub_name; } call qw/^MyAccount::/; # Repeat using the pure object-oriented interface use Aspect::Advice::Before (); use Aspect::Pointcut::Call (); my $advice = Aspect::Advice::Before->new( pointcut => Aspect::Pointcut::Call->new( qr/^MyAccount::/ ), code => sub { print 'called: '. $_->sub_name; }, );
An \*(L"advice\*(R" in \s-1AOP\s0 lingo is composed of a condition (known as a Aspect::Pointcut) and some code that will run when that pointcut is true.
This code is run before, after, or around the target pointcut depending on the particular advice type declaration used.
You do not normally create advice using the constructor. By \*(C`use()\*(C'ing Aspect, you get five advice declaration subroutines imported.
\*(C`before\*(C' is used to indicate code that should run prior to the function being called. See Aspect::Advice::Before for more information.
\*(C`after\*(C' is used to indicate code that should run following the function being called, regardless of whether it returns normally or throws an exception. See Aspect::Advice::After for more information.
\*(C`around\*(C' is used to take deeper control of the call and gives you your own lexical scope between the caller and callee, with a specific \*(C`proceed\*(C' call required in your code to execute the target function. See Aspect::Advice::Around for more information.
When the advice code is called, it is provided with an Advice::Point object which describes the context of the call to the target function, and allows you to change it.
This parameter is provided both via the topic variable $_ (since version 0.90) and additionally as the first parameter to the advice code (which may be deprecated at some point in the future).
If you are creating \*(C`advice\*(C' objects directly via the \s-1OO\s0 interface, you should never use this class directly but instead use the class of the particular type of advice you want to create.
Copyright 2001 by Marcel Gru\*:nauer
Some parts copyright 2009 - 2013 Adam Kennedy.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.