TPath/Selector/Predicated.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« TPath/Selector/Expression.pm ↑ Summary TPath/Math.pm »
1 package TPath::Selector::Predicated;
2 $TPath::Selector::Predicated::VERSION = '1.007';
3 # ABSTRACT: role of selectors that have predicates
4  
5  
6 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use TPath::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use TPath::Test::Node::Complement;
11  
12  
13 with 'TPath::Selector';
14  
15  
16 has predicates => (
17 is => 'ro',
18 isa => 'ArrayRef[TPath::Predicate]',
19 default => sub { [] },
20 auto_deref => 1
21 );
22  
23  
24 sub apply_predicates {
25 my ( $self, @candidates ) = @_;
26 for my $p ( $self->predicates ) {
27 last unless @candidates;
28 @candidates = $p->filter( \@candidates );
29 }
30 return @candidates;
31 }
32  
33 around 'to_string' => sub {
34 my ( $orig, $self, @args ) = @_;
35 my $s = $self->$orig(@args);
36 for my $p ( $self->predicates ) {
37 $p = $p->to_string;
38 $s .= $p =~ /[\s()]/ ? "[ $p ]" : "[$p]";
39 }
40 return $s;
41 };
42  
43 1;
44  
45 __END__
« TPath/Selector/Expression.pm ↑ Summary TPath/Math.pm »