Aspect::Advice.3pm

Langue: en

Version: 2010-05-27 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

NAME

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

SYNOPSIS

   use Aspect;
   
   # "Trace calls to Account subs" created using public interface
   before {
       print 'called: '. shift->sub_name;
   } call qw/^Account::/;
   
   # Trace calls to Account subs" created using object-oriented interface
   use Aspect::Advice;
   
   $advice = Aspect::Advice->new(
       before => sub {
           print 'called: '. shift->sub_name;
      },
      call qw/^Account::/
   );
 
 

DESCRIPTION

An ``advice'' in AOP lingo is composed of a Aspec::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.

AUTHORS

Adam Kennedy <adamk@cpan.org>

Marcel Gru.nauer <marcel@cpan.org>

Ran Eilam <eilara@cpan.org>

Copyright 2001 by Marcel Gru.nauer

Some parts copyright 2009 - 2010 Adam Kennedy.

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