View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Ran Eilam > Aspect-0.12 > Aspect::Modular



Annotate this POD


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


Aspect::Modular - base class for reusable aspects


  # subclassing to create a reusable aspect
  package Aspect::Library::ConstructorTracer;
  use Aspect;
  use base 'Aspect::Modular';
  sub get_advice {
     my ($self, $pointcut) = @_;
        { print 'created object: '. shift->return_value. "\n" }

  # using the new aspect
  package main;
  use Aspect;
  # print message when constructing new Person
  aspect ConstructorTracer => call 'Person::new';


All reusable aspect inherit from this class. Such aspects are created in user code, using the aspect() sub exported by Aspect. You call aspect() with the class name of the reusable aspect (it must exist in the package Aspect::Library), and any parameters (pointcuts, class names, code to run, etc.) the specific aspect may require.

The Wormhole aspect, for example, expects 2 pointcut specs for the wormhole source and target, while the Profiler aspect expects a pointcut object, to select the subs to be profiled.

You create a reusable aspect by subclassing this class, and providing one template method: get_advice(). It is called with all the parameters that were sent when user code created the aspect, and is expected to return Aspect::Advice object/s, that will be installed while the reusable aspect is still in scope. If the aspect() sub is called in void context, the reusable aspect is installed until class reloading or interpreter shutdown.

Typical things a reusable aspect may want to do:


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

You can find examples of reusable aspects in the Aspect::Library package. Aspect::Library::Singleton for example.

syntax highlighting: