| 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: C. It is called with all the parameters |
|
59
|
|
|
|
|
|
|
that were sent when user code created the aspect, and is expected to |
|
60
|
|
|
|
|
|
|
return L object/s, that will be installed while the |
|
61
|
|
|
|
|
|
|
reusable aspect is still in scope. If the C sub is called in |
|
62
|
|
|
|
|
|
|
void context, the reusable aspect is installed until class reloading or |
|
63
|
|
|
|
|
|
|
interpreter shutdown. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Typical things a reusable aspect may want to do: |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over4 |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Install advice on pointcuts specified by the caller |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item * |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Push (vs. OOP pull) subs and base classes into classes specified by |
|
76
|
|
|
|
|
|
|
the caller |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=back |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
See the L pod for a guide to the Aspect module. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
You can find examples of reusable aspects in the C |
|
85
|
|
|
|
|
|
|
package. L for example. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|