PRANG/Graph/Quantity.pm

filter: Statementstmt 88.6% 47 / 53 Branchbran 68.1% 15 / 22 Conditioncond 76.4% 13 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 5 totaltotal 76.3% 87 / 114 CC 18 SCAR 18.7
CC
18
Cov
82%
output
10.2
expected
5.4
accept
5.2
CRAP 6.5
« PRANG/XMLSchema/Types.pm ↑ Summary PRANG/Graph/Seq.pm »
1  
2 package PRANG::Graph::Quantity;
3 11 $PRANG::Graph::Quantity::VERSION = '0.21';
4 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 has 'min' =>
8 is => "ro",
9 isa => "Int",
10 predicate => "has_min",
11 ;
12  
13 11 has 'max' =>
14 is => "ro",
15 isa => "Int",
16 predicate => "has_max",
17 ;
18  
19 11 has 'child' =>
20 is => "ro",
21 isa => "PRANG::Graph::Node",
22 required => 1,
23 ;
24  
25 11 has 'attrName' =>
26 is => "ro",
27 isa => "Str",
28 required => 1,
29 ;
30  
31 136 ▶sub accept_many {1}
Subroutine accept_many: called CC=1 SCAR=0.0
Pod undocumented
32  
33 562 ▶sub accept {
Subroutine accept: called CC=5 SCAR=16.5
Pod undocumented
34 562 my $self = shift;
35 562 my ( $node, $ctx, $lax ) = pos_validated_list(
36 \@_,
37 { isa => 'XML::LibXML::Node' },
38 { isa => 'PRANG::Graph::Context' },
39 { isa => 'Bool', optional => 1 },
40 );
41
42 562 my $found = $ctx->quant_found;
43 562 my $ok = defined $self->child->node_ok($node, $ctx);
44 562 ▶ return if not $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 285 277 562
45 277 ▶ my ($key, $value, $x, $ns) = $self->child->accept($node, $ctx, $lax)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->child->accept($node, $ctx, $lax) or $ctx->exception("internal error: node ok, but then not accepted?", $node) 258 0 258
46 or $ctx->exception(
47 "internal error: node ok, but then not accepted?",
48 $node,
49 );
50 258 $found++;
51 258 $ctx->quant_found($found);
52 258 ▶ if ( $self->has_max and $found > $self->max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max and $found > $self->max) 0 258 258
Condition66%2/3
$self->has_max and $found > $self->max
!ll&&!rl&&r
1241340
MC/DC0%0/2
$self->has_max and $found > $self->max
$self->has_max $found > $self->max
Truth table66%2/3
A and B
A= $self->has_maxB= $found > $self->max
ABresult
0X0
100
111
53 0 $ctx->exception("node appears too many times", $node);
54 }
55 258 ($key, $value, $x, $ns);
56 }
57  
58 488 ▶sub complete {
Subroutine complete: called CC=2 SCAR=7.0
Pod undocumented
59 488 my $self = shift;
60 488 my ( $ctx ) = pos_validated_list(
61 \@_,
62 { isa => 'PRANG::Graph::Context' },
63 );
64
65 488 my $found = $ctx->quant_found;
66 488 ▶ return !( $self->has_min and $found < $self->min );
Condition66%2/3
$self->has_min && $found < $self->min
!ll&&!rl&&r
3731150
MC/DC0%0/2
$self->has_min && $found < $self->min
$self->has_min $found < $self->min
Truth table66%2/3
A && B
A= $self->has_minB= $found < $self->min
ABresult
0X0
100
111
67 }
68  
69 2 ▶sub expected {
Subroutine expected: called CC=4 SCAR=16.9
Pod undocumented
70 2 my $self = shift;
71 2 my ( $ctx ) = pos_validated_list(
72 \@_,
73 { isa => 'PRANG::Graph::Context' },
74 );
75
76 2 my $desc;
77 2 ▶ if ( $self->has_min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_min) { } 0 2 2
78 0 ▶ if ( $self->has_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max) { } 0 0 0
79 0 $desc = "between ".$self->min." and ".$self->max;
80 }
81 else {
82 0 $desc = "at least ".$self->min;
83 }
84 }
85 else {
86 2 ▶ if ( $self->has_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max) { } 2 0 2
87 2 $desc = "optionally up to ".$self->max;
88 }
89 else {
90 0 $desc = "zero or more";
91 }
92 }
93 2 my @expected = $self->child->expected($ctx);
94 2 return("($desc of: ", @expected, ")");
95 }
96  
97 401 ▶sub output {
Subroutine output: called CC=10 SCAR=23.2
Pod undocumented
98 401 my $self = shift;
99 401 my ( $item, $node, $ctx ) = pos_validated_list(
100 \@_,
101 { isa => 'Object' },
102 { isa => 'XML::LibXML::Element' },
103 { isa => 'PRANG::Graph::Context' },
104 );
105
106 401 my $attrName = $self->attrName;
107 401 my $val = $item->$attrName;
108 401 ▶ if ( $self->has_max and $self->max == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_max and $self->max == 1) { } 346 55 401
Condition100%3/3
$self->has_max and $self->max == 1
!ll&&!rl&&r
4510346
MC/DC100%2/2
$self->has_max and $self->max == 1
$self->has_max $self->max == 1
Truth table100%3/3
A and B
A= $self->has_maxB= $self->max == 1
ABresult
0X0
100
111
109  
110 # this is an 'optional'-type thingy
111 346 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 64 282 346
112 64 $self->child->output($item,$node,$ctx,value => $val);
113 }
114 }
115 else {
116  
117 # this is an arrayref-type thingy
118 55 ▶ if ( !$val and !$self->has_min ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $val || $self->has_min) { } 1 54 55
elsif ($val and (ref $val || '') ne 'ARRAY') { } 0 54 54
Condition100%3/3
$val || $self->has_min
l!l&&r!l&&!r
4771
MC/DC100%2/2
$val || $self->has_min
$val $self->has_min
Truth table100%3/3
A || B
A= $valB= $self->has_min
ABresult
1X1
011
000
119  
120 # ok, that's fine
121 }
122 ▶ elsif ( $val and (ref($val)||"") ne "ARRAY" ) {
Condition60%3/5
$val and (ref $val || "") ne "ARRAY"
!ll&&!rl&&r
7470
ref $val || ''
l!l
470
MC/DC50%1/2
$val and (ref $val || "") ne "ARRAY"
$val ref $val
Truth table66%2/3
A and B
A= $valB= ref $val
ABresult
0X0
100
111
123  
124 # that's not
125 0 die "item $item / slot $attrName is $val, not"
126 ."an ArrayRef";
127 }
128 else {
129 54 ▶ for ( my $i = 0; $i <= $#$val; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $val->$#*) 103 54 157
130 103 $ctx->quant_found($i+1);
131 103 $self->child->output(
132 $item,$node,$ctx,
133 value => $val->[$i],
134 slot => $i,
135 );
136 }
137 }
138 }
139 }
140  
141 11 with 'PRANG::Graph::Node';
142  
143 11 1;
144  
145 __END__
« PRANG/XMLSchema/Types.pm ↑ Summary PRANG/Graph/Seq.pm »