-
-
09 Apr 2013 05:38:16 UTC
- Distribution: Aspect
- Module version: 1.04
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Clone repository
- Issues (6)
- Testers (2766 / 27 / 10)
- Kwalitee
Bus factor: 1- 84.41% Coverage
- License: perl_5
- Perl: v5.8.2
- Activity
24 month- Tools
- Download (110.38KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Aspect::Modular - First generation base class for reusable aspects
SYNOPSIS
# 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';
DESCRIPTION
All reusable aspect inherit from this class.
Such aspects are created in user code, using the
aspect()
sub exported by Aspect. You callaspect()
with the class name of the reusable aspect (it must exist in the packageAspect::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 theaspect()
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
AUTHORS
Adam Kennedy <adamk@cpan.org>
Marcel Grünauer <marcel@cpan.org>
Ran Eilam <eilara@cpan.org>
COPYRIGHT
Copyright 2001 by Marcel Grü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.
Module Install Instructions
To install Aspect, copy and paste the appropriate command in to your terminal.
cpanm Aspect
perl -MCPAN -e shell install Aspect
For more information on module installation, please visit the detailed CPAN module installation guide.