Aspect/Pointcut/Or.pm

filter: Statementstmt 78.3% 83 / 106 Branchbran 61.1% 33 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 85.7% 6 / 7 totaltotal 73.7% 132 / 179 SCAR 41.4
CC
36
Cov
72%
compile_weave
13.1
compile_runtime
13.1
__ANON__
12.0
CRAP 63.0
↑ Summary Aspect/Pointcut/And.pm »
1 package Aspect::Pointcut::Or;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use Aspect::Pointcut::Logic ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 21 our $VERSION = '0.97_06';
8 21 our @ISA = 'Aspect::Pointcut::Logic';
9  
10  
11  
12  
13  
14 ######################################################################
15 # Constructor
16  
17 sub new {
18 18 ▶ my $class = shift;
Subroutine new: called CC=5 SCAR=16.2
Pod documented
19 18 my @parts = @_;
20  
21 # Validate the pointcut subexpressions
22 18 foreach my $part ( @parts ) {
23 37 ▶ next if Params::Util::_INSTANCE($part, 'Aspect::Pointcut');
Branch: 1 branch
BranchTrueFalseTotal
if &Params::Util::_INSTANCE($part, "Aspect::Pointcut") 37 0 37
24 0 Carp::croak("Attempted to apply pointcut logic to non-pointcut '$part'");
25 }
26  
27 # Collapse nested or statements at constructor time so we don't have
28 # to do so multiple times later on during currying.
29 18 ▶ while ( scalar grep { $_->isa('Aspect::Pointcut::Or') } @parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({$_->isa("Aspect::Pointcut::Or");} @parts)) 6 18 24
30 @parts = map {
31 6 ▶ $_->isa('Aspect::Pointcut::Or') ? @$_ : $_
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Aspect::Pointcut::Or') ? : 6 6 12
32 } @parts;
33 }
34  
35 18 $class->SUPER::new(@parts);
36 }
37  
38  
39  
40  
41  
42 ######################################################################
43 # Weaving Methods
44  
45 sub compile_weave {
46 3 ▶ my $self = shift;
Subroutine compile_weave: called CC=7 SCAR=25.7
Pod documented
47 3 my @children = map { $_->compile_weave } @$self;
48  
49 # Collapse string conditions together,
50 # and further collapse code conditions together.
51 3 my @string = ();
52 3 my @code = ();
53 3 foreach my $child ( @children ) {
54 # Short-cut if we contain any purely runtime pointcuts
55 6 ▶ unless ( ref $child ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $child) 6 0 6
56 6 ▶ return 1 if $child eq 1;
Branch: 1 branch
BranchTrueFalseTotal
if $child eq 1 0 6 6
57 6 push @string, $child;
58 6 next;
59 }
60 0 ▶ if ( @string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@string) 0 0 0
61 0 my $group = join ' or ', map { "( $_ )" } @string;
62 0 push @code, eval "sub () { $group }";
63 0 @string = ();
64 }
65 0 push @code, $child;
66 }
67  
68 3 ▶ if ( @string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@string) 3 0 3
69 3 my $group = join ' or ', map { "( $_ )" } @string;
70 3 ▶ unless ( @code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@code) 3 0 3
71 # This is the only thing we have
72 3 return $group;
73 }
74 0 push @code, eval "sub () { $group }";
75 }
76  
77 # Join the groups
78 return sub {
79 0 ▶ foreach my $child ( @code ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 0 ▶ return 0 unless $child->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$child() 0 0 0
81 }
82 0 return 1;
83 0 };
84  
85 }
86  
87 sub compile_runtime {
88 1 ▶ my $self = shift;
Subroutine compile_runtime: called CC=7 SCAR=25.7
Pod documented
89 1 my @children = map { $_->compile_runtime } @$self;
90  
91 # Collapse string conditions together,
92 # and further collapse code conditions together.
93 1 my @string = ();
94 1 my @code = ();
95 1 foreach my $child ( @children ) {
96 # Short-cut if we contain any purely runtime pointcuts
97 2 ▶ unless ( ref $child ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $child) 2 0 2
98 2 ▶ return 1 if $child eq 1;
Branch: 1 branch
BranchTrueFalseTotal
if $child eq 1 0 2 2
99 2 push @string, $child;
100 2 next;
101 }
102 0 ▶ if ( @string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@string) 0 0 0
103 0 my $group = join ' or ', map { "( $_ )" } @string;
104 0 push @code, eval "sub () { $group }";
105 0 @string = ();
106 }
107 0 push @code, $child;
108 }
109  
110 1 ▶ if ( @string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@string) 1 0 1
111 1 my $group = join ' or ', map { "( $_ )" } @string;
112 1 ▶ unless ( @code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@code) 1 0 1
113 # This is the only thing we have
114 1 return $group;
115 }
116 0 push @code, eval "sub () { $group }";
117 }
118  
119 # Join the groups
120 return sub {
121 0 ▶ foreach my $child ( @code ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
122 0 ▶ return 0 unless $child->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$child() 0 0 0
123 }
124 0 return 1;
125 0 };
126  
127 }
128  
129 sub match_contains {
130 9 ▶ my $self = shift;
Subroutine match_contains: called CC=3 SCAR=11.1
Pod documented
131 9 ▶ my $count = $self->isa($_[0]) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->isa($_[0]) ? : 0 9 9
132 9 foreach my $child ( @$self ) {
133 18 $count += $child->match_contains($_[0]);
134 }
135 9 return $count;
136 }
137  
138 sub match_runtime {
139 7 ▶ my $self = shift;
Subroutine match_runtime: called CC=3 SCAR=11.0
Pod undocumented
140 7 foreach my $child ( @$self ) {
141 15 ▶ return 1 if $child->match_runtime;
Branch: 1 branch
BranchTrueFalseTotal
if $child->match_runtime 5 10 15
142 }
143 2 return 0;
144 }
145  
146 sub curry_weave {
147 4 ▶ my $self = shift;
Subroutine curry_weave: called CC=5 SCAR=16.2
Pod documented
148 4 my @list = @$self;
149  
150 # Curry down our children. Any null element always matches, and
151 # therefore in an OR scenario the entire expression always matches.
152 4 my @or = ();
153 4 foreach my $child ( @list ) {
154 8 ▶ my $curried = $child->curry_weave or return;
Branch: 1 branch
BranchTrueFalseTotal
my $curried = $child->curry_weave or return 1 7 8
155 7 push @or, $curried;
156 }
157  
158 # If none are left, curry us away to nothing
159 3 ▶ return unless @or;
Branch: 1 branch
BranchTrueFalseTotal
unless @or 0 3 3
160  
161 # If only one remains, curry us away to just that child
162 3 ▶ return $list[0] if @or == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @or == 1 0 3 3
163  
164 # Create our clone to hold the curried subset
165 3 return ref($self)->new(@or);
166 }
167  
168 sub curry_runtime {
169 7 ▶ my $self = shift;
Subroutine curry_runtime: called CC=8 SCAR=20.8
Pod documented
170 7 my @list = @$self;
171  
172 # Should we strip out the call pointcuts
173 7 my $strip = shift;
174 7 ▶ unless ( defined $strip ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $strip) 6 1 7
175 # Are there any elements that MUST exist at run-time?
176 6 ▶ if ( $self->match_runtime ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->match_runtime) { } 4 2 6
177 # If we have any nested logic that themselves contain
178 # call pointcuts, we can't strip.
179 $strip = not scalar grep {
180 4 ▶ $_->isa('Aspect::Pointcut::Logic')
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("Aspect::Pointcut::Logic") and $_->match_contains("Aspect::Pointcut::Call") 0 13 13
181 and
182 $_->match_contains('Aspect::Pointcut::Call')
183 } @list;
184 } else {
185 # Nothing at runtime, so we can strip
186 2 $strip = 1;
187 }
188 }
189  
190 # Curry down our children
191 8 @list = grep { defined $_ } map {
192 7 ▶ $_->isa('Aspect::Pointcut::Call')
Branch: 2 branches
BranchTrueFalseTotal
$_->isa('Aspect::Pointcut::Call') ? : 13 7 20
$strip ? : 12 1 13
193 ? $strip
194 ? $_->curry_runtime($strip)
195 : $_
196 : $_->curry_runtime($strip)
197 } @list;
198  
199 # If none are left, curry us away to nothing
200 7 ▶ return unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 2 5 7
201  
202 # If only one remains, curry us away to just that child
203 5 ▶ return $list[0] if @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @list == 1 3 2 5
204  
205 # Create our clone to hold the curried subset
206 2 return ref($self)->new( @list );
207 }
208  
209 21 1;
210  
211 __END__
↑ Summary Aspect/Pointcut/And.pm »