File Coverage

blib/lib/Aspect/Pointcut/Not.pm
Criterion Covered Total %
statement 34 41 82.9
branch 12 18 66.6
condition n/a
subroutine 10 12 83.3
pod 6 7 85.7
total 62 78 79.4


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