File Coverage

blib/lib/Aspect/Pointcut/Not.pm
Criterion Covered Total %
statement 31 38 81.5
branch 12 18 66.6
condition n/a
subroutine 9 11 81.8
pod 6 7 85.7
total 58 74 78.3


line stmt bran cond sub pod time code
1             package Aspect::Pointcut::Not;
2              
3 26     26   139 use strict;
  26         2936  
  26         881  
4 26     26   144 use Aspect::Pointcut::Logic ();
  26         49  
  26         14435  
5              
6             our $VERSION = '1.04';
7             our @ISA = 'Aspect::Pointcut::Logic';
8              
9              
10              
11              
12              
13             ######################################################################
14             # Constructor
15              
16             sub new {
17 13     13 1 24 my $class = shift;
18              
19             # Check the thing we are negating
20 13 50       139 unless ( Params::Util::_INSTANCE($_[0], 'Aspect::Pointcut') ) {
21 0         0 Carp::croak("Attempted to apply pointcut logic to non-pointcut '$_[0]'");
22             }
23              
24 13         80 $class->SUPER::new(@_);
25             }
26              
27              
28              
29              
30              
31             ######################################################################
32             # Weaving Methods
33              
34             sub compile_weave {
35 6     6 1 32 my $child = $_[0]->[0]->compile_weave;
36 6 50       28 if ( ref $child ) {
37 0     0   0 return sub { not $child->() };
  0         0  
38             }
39 6 100       22 unless ( $child eq '1' ) {
40 2         13 return "not ( $child )";
41             }
42              
43             # When the child matches everything, the negation doesn't negate
44             # the set of things matched. So we match everything too.
45 4         14 return 1;
46             }
47              
48             sub compile_runtime {
49 4     4 1 19 my $child = $_[0]->[0]->compile_runtime;
50 4 50       12 if ( ref $child ) {
51 0     0   0 return sub { not $child->() };
  0         0  
52             } else {
53 4         19 return "not ( $child )";
54             }
55             }
56              
57             sub match_contains {
58 20     20 1 30 my $self = shift;
59 20         82 my $count = $self->[0]->match_contains($_[0]);
60 20 50       146 return $self->isa($_[0]) ? ++$count : $count;
61             }
62              
63             sub match_runtime {
64 5     5 0 44 $_[0]->[0]->match_runtime;
65             }
66              
67             # Logical not inherits it's curryability from the element contained
68             # within it. We continue to be needed if and only if something below us
69             # continues to be needed as well.
70             sub curry_weave {
71 6     6 1 11 my $self = shift;
72 6 100       26 my $child = $self->[0]->curry_weave or return;
73              
74             # Handle the special case where the collapsing pointcut results
75             # in a "double not". Fetch the child of our child not and return
76             # it directly.
77 2 50       24 if ( $child->isa('Aspect::Pointcut::Not') ) {
78 0         0 return $child->[0];
79             }
80              
81             # Return our clone with the curried child
82 2         5 my $class = ref($self);
83 2         9 return $class->new( $child );
84             }
85              
86             # Logical not inherits it's curryability from the element contained
87             # within it. We continue to be needed if and only if something below us
88             # continues to be needed as well.
89             # For cleanliness (and to avoid accidents) we make a copy of ourself
90             # in case our child curries to something other than it's pure self.
91             sub curry_runtime {
92 6     6 1 13 my $self = shift;
93 6 100       32 my $child = $self->[0]->curry_runtime or return;
94              
95             # Handle the special case where the collapsing pointcut results
96             # in a "double not". Fetch the child of our child not and return
97             # it directly.
98 4 50       29 if ( $child->isa('Aspect::Pointcut::Not') ) {
99 0         0 return $child->[0];
100             }
101              
102             # Return our clone with the curried child
103 4         10 my $class = ref($self);
104 4         12 return $class->new( $child );
105             }
106              
107             1;
108              
109             __END__