File Coverage

lib/Aspect/Modular.pm
Criterion Covered Total %
statement 12 13 92.3
branch n/a
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 16 20 80.0


line stmt bran cond sub pod time code
1             package Aspect::Modular;
2              
3 1     1   6 use strict;
  1         2  
  1         39  
4 1     1   6 use warnings;
  1         1  
  1         27  
5 1     1   6 use Carp;
  1         3  
  1         140  
6              
7             # creating --------------------------------------------------------------------
8              
9             sub new {
10 2     2 0 2010 my $self = bless {}, shift;
11 2         13 $self->{advice} = [$self->get_advice(@_)];
12 2         8 return $self;
13             }
14              
15             # template methods ------------------------------------------------------------
16              
17 0     0 0   sub get_advice {}
18              
19             1;
20              
21             =head1 NAME
22              
23             Aspect::Modular - base class for reusable aspects
24              
25             =head1 SYNOPSIS
26              
27             # subclassing to create a reusable aspect
28             package Aspect::Library::ConstructorTracer;
29             use Aspect;
30             use base 'Aspect::Modular';
31             sub get_advice {
32             my ($self, $pointcut) = @_;
33             after
34             { print 'created object: '. shift->return_value. "\n" }
35             $pointcut;
36             }
37              
38             # using the new aspect
39             package main;
40             use Aspect;
41             # print message when constructing new Person
42             aspect ConstructorTracer => call 'Person::new';
43              
44             =head1 DESCRIPTION
45              
46             All reusable aspect inherit from this class. Such aspects are created in
47             user code, using the C sub exported by L. You
48             call C with the class name of the reusable aspect (it must
49             exist in the package C), and any parameters (pointcuts,
50             class names, code to run, etc.) the specific aspect may require.
51              
52             The L aspect, for example, expects 2
53             pointcut specs for the wormhole source and target, while the
54             L aspect expects a pointcut object,
55             to select the subs to be profiled.
56              
57             You create a reusable aspect by subclassing this class, and providing one
58             I