/usr/share/perl5/Aspect/Pointcut/Or.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 | package Aspect::Pointcut::Or;
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 or statements at constructor time so we don't have
# to do so multiple times later on during currying.
while ( scalar grep { $_->isa('Aspect::Pointcut::Or') } @parts ) {
@parts = map {
$_->isa('Aspect::Pointcut::Or') ? @$_ : $_
} @parts;
}
$class->SUPER::new(@parts);
}
######################################################################
# Weaving Methods
sub compile_weave {
my $self = shift;
my @children = map { $_->compile_weave } @$self;
# Collapse string conditions together,
# and further collapse code conditions together.
my @string = ();
my @code = ();
foreach my $child ( @children ) {
# Short-cut if we contain any purely runtime pointcuts
unless ( ref $child ) {
return 1 if $child eq 1;
push @string, $child;
next;
}
if ( @string ) {
my $group = join ' or ', map { "( $_ )" } @string;
push @code, eval "sub () { $group }";
@string = ();
}
push @code, $child;
}
if ( @string ) {
my $group = join ' or ', 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;
my @children = map { $_->compile_runtime } @$self;
# Collapse string conditions together,
# and further collapse code conditions together.
my @string = ();
my @code = ();
foreach my $child ( @children ) {
# Short-cut if we contain any purely runtime pointcuts
unless ( ref $child ) {
return 1 if $child eq 1;
push @string, $child;
next;
}
if ( @string ) {
my $group = join ' or ', map { "( $_ )" } @string;
push @code, eval "sub () { $group }";
@string = ();
}
push @code, $child;
}
if ( @string ) {
my $group = join ' or ', 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 $count = $self->isa($_[0]) ? 1 : 0;
foreach my $child ( @$self ) {
$count += $child->match_contains($_[0]);
}
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. Any null element always matches, and
# therefore in an OR scenario the entire expression always matches.
my @or = ();
foreach my $child ( @list ) {
my $curried = $child->curry_weave or return;
push @or, $curried;
}
# If none are left, curry us away to nothing
return unless @or;
# If only one remains, curry us away to just that child
return $list[0] if @or == 1;
# Create our clone to hold the curried subset
return ref($self)->new(@or);
}
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::Or - Logical 'or' pointcut
=head1 SYNOPSIS
use Aspect;
# High-level creation
my $pointcut1 = call 'one' | call 'two' | call 'three';
# Manual creation
my $pointcut2 = Aspect::Pointcut::Or->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
|