/usr/share/perl5/Aspect/Pointcut/And.pm is in libaspect-perl 1.04-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | package Aspect::Pointcut::And;
use strict;
use Aspect::Pointcut::Logic ();
our $VERSION = '1.04';
our @ISA = 'Aspect::Pointcut::Logic';
######################################################################
# Constructor
sub new {
my $class = shift;
my @parts = @_;
# Validate the pointcut subexpressions
foreach my $part ( @parts ) {
next if Params::Util::_INSTANCE($part, 'Aspect::Pointcut');
Carp::croak("Attempted to apply pointcut logic to non-pointcut '$part'");
}
# Collapse nested and statements at constructor time so we don't have
# to do so multiple times later on during currying.
while ( scalar grep { $_->isa('Aspect::Pointcut::And') } @parts ) {
@parts = map {
$_->isa('Aspect::Pointcut::And') ? @$_ : $_
} @parts;
}
$class->SUPER::new(@parts);
}
######################################################################
# Weaving Methods
sub compile_weave {
my $self = shift;
# Handle special cases
my @children = grep {
ref $_ or $_ ne 1
} map {
$_->compile_weave
} @$self;
unless ( @children ) {
# Potential bug, but why would we legitimately be empty
return 1;
}
if ( @children == 1 ) {
return $children[0];
}
# Collapse string conditions together,
# and further collapse code conditions together.
my @string = ();
my @code = ();
foreach my $child ( @children ) {
unless ( ref $child ) {
push @string, $child;
next;
}
if ( @string ) {
my $group = join ' and ', map { "( $_ )" } @string;
push @code, eval "sub () { $group }";
@string = ();
}
push @code, $child;
}
if ( @string ) {
my $group = join ' and ', map { "( $_ )" } @string;
unless ( @code ) {
# This is the only thing we have
return $group;
}
push @code, eval "sub () { $group }";
}
# Join the groups
return sub {
foreach my $child ( @code ) {
return 0 unless $child->();
}
return 1;
};
}
sub compile_runtime {
my $self = shift;
# Handle special cases
my @children = grep {
ref $_ or $_ ne 1
} map {
$_->compile_runtime
} @$self;
unless ( @children ) {
# Potential bug, but why would we legitimately be empty
return 1;
}
if ( @children == 1 ) {
return $children[0];
}
# Collapse string conditions together,
# and further collapse code conditions together.
my @string = ();
my @code = ();
foreach my $child ( @children ) {
unless ( ref $child ) {
push @string, $child;
next;
}
if ( @string ) {
my $group = join ' and ', map { "( $_ )" } @string;
push @code, eval "sub () { $group }";
@string = ();
}
push @code, $child;
}
if ( @string ) {
my $group = join ' and ', map { "( $_ )" } @string;
unless ( @code ) {
# This is the only thing we have
return $group;
}
push @code, eval "sub () { $group }";
}
# Join the groups
return sub {
foreach my $child ( @code ) {
return 0 unless $child->();
}
return 1;
};
}
sub match_contains {
my $self = shift;
my $type = shift;
my $count = $self->isa($type) ? 1 : 0;
foreach my $child ( @$self ) {
$count += $child->match_contains($type);
}
return $count;
}
sub match_runtime {
my $self = shift;
foreach my $child ( @$self ) {
return 1 if $child->match_runtime;
}
return 0;
}
sub curry_weave {
my $self = shift;
my @list = @$self;
# Curry down our children. Anything that is not relevant at weave
# time is considered to always match, but curries to null.
# In an AND scenario, any "always" match can be savely removed.
@list = grep { defined $_ } map { $_->curry_weave } @list;
# If none are left, curry us away to nothing
return unless @list;
# If only one remains, curry us away to just that child
return $list[0] if @list == 1;
# Create our clone to hold the curried subset
return ref($self)->new( @list );
}
sub curry_runtime {
my $self = shift;
my @list = @$self;
# Should we strip out the call pointcuts
my $strip = shift;
unless ( defined $strip ) {
# Are there any elements that MUST exist at run-time?
if ( $self->match_runtime ) {
# If we have any nested logic that themselves contain
# call pointcuts, we can't strip.
$strip = not scalar grep {
$_->isa('Aspect::Pointcut::Logic')
and
$_->match_contains('Aspect::Pointcut::Call')
} @list;
} else {
# Nothing at runtime, so we can strip
$strip = 1;
}
}
# Curry down our children
@list = grep { defined $_ } map {
$_->isa('Aspect::Pointcut::Call')
? $strip
? $_->curry_runtime($strip)
: $_
: $_->curry_runtime($strip)
} @list;
# If none are left, curry us away to nothing
return unless @list;
# If only one remains, curry us away to just that child
return $list[0] if @list == 1;
# Create our clone to hold the curried subset
return ref($self)->new( @list );
}
1;
__END__
=pod
=head1 NAME
Aspect::Pointcut::And - Logical 'and' pointcut
=head1 SYNOPSIS
use Aspect;
# High-level creation
my $pointcut1 = call 'one' & call 'two' & call 'three';
# Manual creation
my $pointcut2 = Aspect::Pointcut::And->new(
Aspect::Pointcut::Call->new('one'),
Aspect::Pointcut::Call->new('two'),
Aspect::Pointcut::Call->new('three'),
);
=head1 DESCRIPTION
B<Aspect::Pointcut::And> is a logical condition, which is used
to create higher-order conditions from smaller parts.
It takes two or more conditions, and applies appropriate logic during the
various calculations that produces a logical set-wise 'and' result.
=head1 AUTHORS
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
Marcel GrE<uuml>nauer E<lt>marcel@cpan.orgE<gt>
Ran Eilam E<lt>eilara@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright 2001 by Marcel GrE<uuml>nauer
Some parts copyright 2009 - 2013 Adam Kennedy.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|