Data/ZPath.pm

filter: Statementstmt 100% 76 / 76 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 17 / 17 Podpod 100% 6 / 6 totaltotal 95.0% 115 / 121 CC 13 SCAR 11.4
CC
13
Cov
96%
each
7.2
evaluate
4.0
last
2.0
CRAP 3.1
« Text/ZTemplate.pm ↑ Summary Data/ZPath/NodeList.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Data::ZPath;
5  
6 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Data::ZPath::_Ctx;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Data::ZPath::_Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Data::ZPath::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Data::ZPath::NodeList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Data::ZPath::_Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Data::ZPath::_ScalarProxy;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Data::ZPath::_Evaluate;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 our $DEBUG = 0;
17  
18 8 our $VERSION = '0.001000';
19  
20 8 our @CARP_NOT = qw(
21 Data::ZPath::_Ctx
22 Data::ZPath::_Lexer
23 Data::ZPath::Node
24 Data::ZPath::NodeList
25 Data::ZPath::_Parser
26 Data::ZPath::_ScalarProxy
27 Data::ZPath::_Evaluate
28 );
29  
30 8 for my $pkg ( @CARP_NOT ) {
31 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 56 *{"${pkg}::CARP_NOT"} = \@CARP_NOT;
33 }
34  
35 8 our $Epsilon = 1e-08;
36 8 our $UseBigInt = !!1;
37 8 our $XmlIgnoreWS = !!1;
38  
39 377 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
40 377 my ( $class, $expr ) = @_;
41 377 ▶ croak "Missing expression" unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 1 376 377
42  
43 376 my $self = bless {
44 expr_src => $expr,
45 terms => Data::ZPath::_Parser::_parse_top_level_terms($expr),
46 }, $class;
47  
48 367 return $self;
49 }
50  
51 375 ▶sub evaluate {
Subroutine evaluate: called CC=4 SCAR=13.9
Pod documented
52 375 my ( $self, $root, %opts ) = @_;
53 375 my $wantarray = wantarray;
54  
55 375 my $ctx = Data::ZPath::_Ctx->new($root);
56 375 my @out;
57  
58 375 for my $term (@{$self->{terms}}) {
59 431 push @out, Data::ZPath::_Evaluate::_eval_expr($term, $ctx);
60 431 ▶ last if ( $opts{first} and @out );
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"first"} and @out 5 426 431
Condition100%3/3
$opts{"first"} and @out
!ll&&!rl&&r
42515
MC/DC100%2/2
$opts{"first"} and @out
$opts{"first"} @out
Truth table100%3/3
A and B
A= $opts{"first"}B= @out
ABresult
0X0
100
111
61 }
62  
63 375 return Data::ZPath::NodeList->_new_or_list(@out);
64 }
65  
66 15 ▶sub all {
Subroutine all: called CC=1 SCAR=0.0
Pod documented
67 15 my ( $self, $root ) = @_;
68 15 map $_->value, $self->evaluate( $root )->all;
69 }
70  
71 5 ▶sub first {
Subroutine first: called CC=2 SCAR=6.9
Pod documented
72 5 my ( $self, $root ) = @_;
73 5 ▶ my $found = $self->evaluate($root, first => 1)->first
Branch: 1 branch
BranchTrueFalseTotal
my $found = $self->evaluate($root, "first", 1)->first or return undef 4 1 5
74 or return undef;
75 4 return $found->value;
76 }
77  
78 1 ▶sub last {
Subroutine last: called CC=2 SCAR=7.1
Pod documented
79 1 my ( $self, $root ) = @_;
80 1 ▶ my $found = $self->evaluate($root)->last
Branch: 1 branch
BranchTrueFalseTotal
my $found = $self->evaluate($root)->last or return undef 1 0 1
81 or return undef;
82 1 return $found->value;
83 }
84  
85 3 ▶sub each {
Subroutine each: called CC=7 SCAR=19.7
Pod documented
86 3 my ( $self, $root, $cb ) = @_;
87 3 ▶ croak "each() requires a coderef" unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 1 2 3
88  
89 2 my $ctx = Data::ZPath::_Ctx->new($root);
90 2 for my $term (@{$self->{terms}}) {
91 2 my @res = Data::ZPath::_Evaluate::_eval_expr($term, $ctx);
92  
93 2 for my $node (@res) {
94 2 my $slot = $node->slot;
95 2 ▶ croak "each() can only mutate Perl map/list scalars (not XML)" unless $slot && ref($slot) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $slot and ref $slot eq "CODE" 0 2 2
Condition33%1/3
$slot and ref $slot eq "CODE"
!ll&&!rl&&r
002
MC/DC0%0/2
$slot and ref $slot eq "CODE"
$slot ref $slot eq "CODE"
Truth table33%1/3
A and B
A= $slotB= ref $slot eq "CODE"
ABresult
0X0
100
111
96  
97 2 tie my $proxy, 'Data::ZPath::_ScalarProxy', $slot;
98 2 $cb->() for $proxy;
99 }
100 }
101  
102 2 return;
103 }
104  
105 8 1;
106  
107 __END__
« Text/ZTemplate.pm ↑ Summary Data/ZPath/NodeList.pm »