Aspect::Modular(3pm)

Aspect::Modular3pm

First generation base class for reusable aspects

Usage

  # Subclassing to create a reusable aspect
  package Aspect::Library::ConstructorTracer;
  
  use strict;
  use base 'Aspect::Modular';
  use Aspect::Advice::After ();
  
  sub get_advice {
     my $self     = shift;
     my $pointcut = shift;
     return Aspect::Advice::After->new(
         lexical  => $self->lexical,
         pointcut => $pointcut,
         code     => sub {
             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';

Overview

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:

•

Install advice on pointcuts specified by the caller

•

Push (vs. OOP pull) subs and base classes into classes specified by the caller

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 5 times.

  1. 6.0
  2. 7
  3. 8–10
  4. 11
  5. 12
  6. 13

Authors

Adam Kennedy <[email protected]>

Marcel Grünauer <[email protected]>

Ran Eilam <[email protected]>

From libaspect-perl 1.04-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.