blib/lib/XML/XForms/Validate.pm

filter: Statementstmt 94.8% 660 / 696 Branchbran 84.5% 230 / 272 Conditioncond 70.5% 108 / 153 MC/DCmcdc 48.3% 44 / 91 Subroutinesub 88.6% 70 / 79 Podpod 9.0% 3 / 33 totaltotal 84.2% 1115 / 1324 CC 231 SCAR 26.5
CC
231
Cov
89%
checkBinds
29.5
new
27.4
validate
26.0
CRAP 14.2
↑ Summary
1 package XML::XForms::Validate;
2  
3 18 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 our $VERSION = '0.9';
7  
8 18 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use XML::Schema::Type::Builtin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use Time::Seconds;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 18 ▶use fields qw(base model refs instances submissions parser schemas binds);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use constant NSURI_XF => 'http://www.w3.org/2002/xforms';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use constant NSURI_XSD => 'http://www.w3.org/2001/XMLSchema-datatypes';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use constant NSURI_XSI => 'http://www.w3.org/2001/XMLSchema-instance';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶use constant NSURI_XS => 'http://www.w3.org/2001/XMLSchema';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use constant NSURI_XI => 'http://www.w3.org/2001/XInclude';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 our @EXPORT_OK = qw(&validate &normalize);
22  
23 # General-purpose globals. Each object uses specialized private instances as well.
24 18 my $parser = new XML::LibXML;
25  
26 18 my $xpc = new XML::LibXML::XPathContext(new XML::LibXML::Document());
27 18 $xpc->registerNs('xf', NSURI_XF);
28  
29 18 my $cbs = new XML::LibXML::InputCallback();
30 0 ▶$cbs->register_callbacks([ sub {die}, sub {die}, sub {die}, sub {die} ]);
Subroutine __ANON__: not called CC=1 SCAR=4.1
Subroutine __ANON__: not called CC=1 SCAR=4.1
Subroutine __ANON__: not called CC=1 SCAR=4.1
Subroutine __ANON__: not called CC=1 SCAR=4.1
31  
32 18 my $doc = new XML::LibXML::Document();
33  
34 39 ▶sub normalize {
Subroutine normalize: called CC=10 SCAR=23.2
Pod documented
35 39 ▶ shift if UNIVERSAL::isa($_[0],'XML::XForms::Validate');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "XML::XForms::Validate") 27 12 39
36 39 my ($dom, $noclean) = @_;
37 39 ▶ return $dom if !ref($dom);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dom 1 38 39
38 0 ▶ my $parser = new XML::LibXML(ext_ent_handler => sub {die});
Subroutine __ANON__: not called CC=1 SCAR=1.2
39 38 $parser->validation(0);
40 38 $parser->load_ext_dtd(0);
41 38 $parser->expand_xinclude(0);
42 38 $parser->expand_entities(0);
43 38 $parser->input_callbacks($cbs);
44 38 $parser->clean_namespaces(1);
45 38 $parser->no_network(1);
46 38 ▶ $dom = { '' => $dom } if ref($dom) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dom ne "HASH" 37 1 38
47 38 my $result = { };
48 38 foreach my $id (keys %$dom) {
49 39 my $old = $$dom{$id};
50 39 ▶ $old = $old->documentElement if $old->can('documentElement');
Branch: 1 branch
BranchTrueFalseTotal
if $old->can("documentElement") 12 27 39
51 39 my $new = $parser->parse_string($old->toStringC14N(0));
52 39 normalizeRecursive($new->documentElement, $noclean, {});
53 39 ▶ $$result{$id} ||= $parser->parse_string($new->documentElement->toStringC14N(0));
Condition33%1/3
$result->{$id} ||= $parser->parse_string($new->documentElement->toStringC14N(0))
l!l&&r!l&&!r
0390
MC/DC0%0/2
$result->{$id} ||= $parser->parse_string($new->documentElement->toStringC14N(0))
$result->{$id} $parser->parse_string($new->documentElement->toStringC14N(0))
Truth table33%1/3
A ||= B
A= $result->{$id}B= $parser->parse_string($new->documentElement->toStringC14N(0))
ABresult
1X1
011
000
54 39 ▶ $$result{''} = $$result{$id} if ($id ne '' && $$dom{$id} eq $$dom{''});
Branch: 1 branch
BranchTrueFalseTotal
if $id ne "" and $dom->{$id} eq $dom->{""} 0 39 39
Condition66%2/3
$id ne "" and $dom->{$id} eq $dom->{""}
!ll&&!rl&&r
3810
MC/DC0%0/2
$id ne "" and $dom->{$id} eq $dom->{""}
$id ne "" $dom->{$id} eq $dom->{""}
Truth table66%2/3
A and B
A= $id ne ""B= $dom->{$id} eq $dom->{""}
ABresult
0X0
100
111
55 }
56  
57 38 ▶ return (ref($_[0]) eq 'HASH'?$result:$$result{''});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 37 38
58 }
59  
60 18 my %allowed = map { (eval('&XML_'.$_.'_NODE') => 1) } qw(ELEMENT ATTRIBUTE TEXT);
61 18 $allowed{&XML_NAMESPACE_DECL} = 1;
62 669 ▶sub normalizeRecursive {
Subroutine normalizeRecursive: called CC=17 SCAR=28.5
Pod undocumented
63 669 my ($parent, $noclean, $usedns) = @_;
64  
65 669 my %newns;
66 669 ▶ $newns{($parent->prefix||'').'='.($parent->namespaceURI||'')} = 1;
Condition75%3/4
$parent->prefix || ''
l!l
0669
$parent->namespaceURI || ''
l!l
1668
MC/DC0%0/1
$parent->prefix || ''
$parent->prefix
MC/DC100%1/1
$parent->namespaceURI || ''
$parent->namespaceURI
Truth table50%1/2
A
A= $parent->prefix
Aresult
11
00
Truth table100%2/2
A
A= $parent->namespaceURI
Aresult
11
00
67 669 foreach my $attr ($parent->attributes) {
68 55 ▶ next if !$attr || $attr->nodeType == XML_NAMESPACE_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if not $attr or $attr->nodeType == 18 11 44 55
Condition66%2/3
not $attr or $attr->nodeType == 18
l!l&&r!l&&!r
01144
MC/DC50%1/2
not $attr or $attr->nodeType == 18
not $attr $attr->nodeType == 18
Truth table66%2/3
not(A) or B
A= not $attrB= $attr->nodeType == 18
ABresult
1X1
011
000
69 44 ▶ $newns{($attr->prefix||'').'='.($attr->namespaceURI||'')} = 1;
Condition100%4/4
$attr->prefix || ''
l!l
242
$attr->namespaceURI || ''
l!l
242
MC/DC100%1/1
$attr->prefix || ''
$attr->prefix
MC/DC100%1/1
$attr->namespaceURI || ''
$attr->namespaceURI
Truth table100%2/2
A
A= $attr->prefix
Aresult
11
00
Truth table100%2/2
A
A= $attr->namespaceURI
Aresult
11
00
70 }
71  
72 669 foreach my $node ($parent->childNodes) {
73 632 ▶ if ($allowed{$node->nodeType} && ($node->namespaceURI||'') ne NSURI_XI) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allowed{$node->nodeType} and ($node->namespaceURI || '') ne 'http://www.w3.org/2001/XInclude') { } 630 2 632
Condition100%5/5
$allowed{$node->nodeType} and ($node->namespaceURI || "") ne "http://www.w3.org/2001/XInclude"
!ll&&!rl&&r
11630
$node->namespaceURI || ''
l!l
1630
MC/DC100%2/2
$allowed{$node->nodeType} and ($node->namespaceURI || "") ne "http://www.w3.org/2001/XInclude"
$allowed{$node->nodeType} $node->namespaceURI
Truth table100%3/3
A and B
A= $allowed{$node->nodeType}B= $node->namespaceURI
ABresult
0X0
100
111
74 630 normalizeRecursive($node, \%newns);
75 } else {
76 2 $parent->removeChild($node);
77 }
78 }
79  
80 669 ▶ if (!$noclean) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $noclean) 38 631 669
81 38 foreach my $ns ($parent->getNamespaces) {
82 10 ▶ my $prefix = $ns->nodeName || '';
Condition50%1/2
$ns->nodeName || ''
l!l
100
MC/DC0%0/1
$ns->nodeName || ''
$ns->nodeName
Truth table50%1/2
A
A= $ns->nodeName
Aresult
11
00
83 10 $prefix =~ s/^xmlns:?//;
84 10 ▶ next if delete $newns{$prefix.'='.($ns->nodeValue||'')};
Branch: 1 branch
BranchTrueFalseTotal
if delete $newns{$prefix . '=' . ($ns->nodeValue || "")} 3 7 10
Condition50%1/2
$ns->nodeValue || ''
l!l
100
MC/DC0%0/1
$ns->nodeValue || ''
$ns->nodeValue
Truth table50%1/2
A
A= $ns->nodeValue
Aresult
11
00
85 7 $parent->setNamespaceDeclURI($prefix, undef);
86 }
87 38 %$usedns = (%$usedns, %newns);
88 }
89 }
90  
91 29 ▶sub new {
Subroutine new: called CC=27 SCAR=33.1
Pod documented
92 29 my XML::XForms::Validate $self = shift;
93 29 ▶ $self = fields::new($self) unless (ref $self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 29 0 29
94  
95 29 $self->{parser} = new XML::LibXML();
96 29 $self->{parser}->no_network(1);
97 29 $self->{parser}->input_callbacks($cbs);
98 0 ▶ $self->{parser}->{ext_ent_handler} = sub { die };
Subroutine __ANON__: not called CC=1 SCAR=1.2
99 29 $self->{parser}->clean_namespaces(1);
100 29 $self->{parser}->expand_xinclude(0);
101 29 $self->{parser}->validation(0);
102 29 $self->{parser}->load_ext_dtd(0);
103 29 $self->{parser}->no_network(1);
104  
105 29 my %options = @_;
106 29 my ($xforms, $model, $base) = @options{'xforms', 'model', 'base'};
107 29 $xforms = $self->getDom($xforms, $base);
108  
109 28 my $default;
110 28 my ($id, $node);
111 28 foreach my $m ($xpc->findnodes('//xf:model', $xforms)) {
112 40 $id = $m->getAttribute('id');
113 40 ▶ $id = '' if !defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 2 38 40
114 40 ▶ $default = $id if !defined $default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default 28 12 40
115 40 ▶ next if defined $model && $model ne $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $model and $model ne $id 12 28 40
Condition100%3/3
defined $model and $model ne $id
!ll&&!rl&&r
171112
MC/DC100%2/2
defined $model and $model ne $id
defined $model $model ne $id
Truth table100%3/3
A and B
A= defined $modelB= $model ne $id
ABresult
0X0
100
111
116 28 $self->{model} = $m;
117 28 $model = $id;
118 28 last;
119 }
120  
121 28 my $anon = 0;
122 28 $self->processBinds($self->{model}, [], $anon);
123  
124 28 $self->{refs} = [];
125 28 $self->processRefs($xpc->findnodes('/*[1]', $xforms), [], $model, $default);
126  
127 28 ▶ if (!$xpc->findnodes('./xf:instance', $self->{model})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xpc->findnodes("./xf:instance", $self->{"model"})) 15 13 28
128 15 my $instelt = $xforms->createElementNS(NSURI_XF, 'xf:instance');
129 15 $self->{model}->addChild($instelt);
130 15 $node = $xforms->createElement('instanceData');
131 15 $instelt->addChild($node);
132  
133 15 foreach my $ui (@{$self->{refs}}) {
134 25 ▶ next unless @$ui == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$ui == 1 0 25 25
135 25 $node->addChild($xforms->createElement($$ui[0]));
136 }
137 }
138  
139 28 $self->{instances} = {};
140 28 $self->{schemas} = {};
141 28 foreach my $instance ($xpc->findnodes('./xf:instance', $self->{model})) {
142 31 $id = $instance->getAttribute('id');
143 31 ▶ $id = '' if !defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 23 8 31
144 31 ▶ if (defined (my $link = $instance->getAttribute('src'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $link = $instance->getAttribute('src'))) { } 0 31 31
145 0 $node = $self->{parser}->parse_file($link);
146 } else {
147 31 ($node) = $xpc->findnodes('./*', $instance);
148 31 $node = $self->{parser}->parse_string($node->toStringC14N());
149 }
150 31 $node = $node->documentElement();
151 31 ▶ $self->{instances}{$id} ||= $node;
Condition33%1/3
$self->{"instances"}{$id} ||= $node
l!l&&r!l&&!r
0310
MC/DC0%0/2
$self->{"instances"}{$id} ||= $node
$self->{"instances"}{$id} $node
Truth table33%1/3
A ||= B
A= $self->{"instances"}{$id}B= $node
ABresult
1X1
011
000
152 31 ▶ $self->{instances}{''} ||= $node;
Condition66%2/3
$self->{"instances"}{""} ||= $node
l!l&&r!l&&!r
2650
MC/DC0%0/2
$self->{"instances"}{""} ||= $node
$self->{"instances"}{""} $node
Truth table66%2/3
A ||= B
A= $self->{"instances"}{""}B= $node
ABresult
1X1
011
000
153  
154 31 my %loc;
155 my $loc;
156 31 $loc = $node->getAttributeNS(NSURI_XSI, 'schemaLocation');
157 31 ▶ %loc = split(/\s+/, $loc) if $loc;
Branch: 1 branch
BranchTrueFalseTotal
if $loc 1 30 31
158 31 $loc = $node->getAttributeNS(NSURI_XSI, 'noNamespaceSchemaLocation');
159 31 ▶ $loc{''} = $loc if $loc;
Branch: 1 branch
BranchTrueFalseTotal
if $loc 3 28 31
160 31 ▶ my $nsuri = $node->namespaceURI || '';
Condition100%2/2
$node->namespaceURI || ''
l!l
328
MC/DC100%1/1
$node->namespaceURI || ''
$node->namespaceURI
Truth table100%2/2
A
A= $node->namespaceURI
Aresult
11
00
161 $self->{schemas}{$id} = new XML::LibXML::Schema(location => $loc{$nsuri})
162 31 ▶ if exists $loc{$nsuri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $loc{$nsuri} 3 28 31
163 }
164  
165 28 $self->{submissions} = {};
166 28 foreach my $s ($xpc->findnodes('./xf:submission', $self->{model})) {
167 32 $id = $s->getAttribute('id');
168 32 ▶ next unless defined $id && !$self->{submissions}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and not $self->{"submissions"}{$id} 1 31 32
Condition66%2/3
defined $id and not $self->{"submissions"}{$id}
!ll&&!rl&&r
1031
MC/DC50%1/2
defined $id and not $self->{"submissions"}{$id}
defined $id not $self->{"submissions"}{$id}
Truth table66%2/3
A and not(B)
A= defined $idB= not $self->{"submissions"}{$id}
ABresult
0X0
100
111
169 31 $self->{submissions}{$id} = { id => $id };
170 31 ▶ if (my $b = $s->getAttribute('bind')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $s->getAttribute('bind')) { } 3 28 31
171 3 ▶ die "Invalid XForms document: referenced bind \"$b\" not found" unless exists $self->{binds}{$b};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binds"}{$b} 0 3 3
172 3 $self->{submissions}{$id}{'ref'} = [ @{$self->{binds}{$s->getAttribute('bind')}{nodeset}} ];
173 } else {
174 28 ▶ $self->{submissions}{$id}{'ref'} = [ $s->getAttribute('ref') || '/' ];
Condition100%2/2
$s->getAttribute('ref') || '/'
l!l
325
MC/DC100%1/1
$s->getAttribute('ref') || '/'
$s->getAttribute('ref')
Truth table100%2/2
A
A= $s->getAttribute('ref')
Aresult
11
00
175 }
176 31 ▶ $self->{submissions}{''} = $self->{submissions}{$id} unless $self->{submissions}{''};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"submissions"}{""} 27 4 31
177 }
178 28 ▶ die "submission element is missing in model $model" unless %{$self->{submissions}};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$self->{"submissions"};} 1 27 28
179  
180 27 return $self;
181 }
182  
183 79 ▶sub getDom {
Subroutine getDom: called CC=8 SCAR=20.9
Pod undocumented
184 79 my XML::XForms::Validate $self = shift;
185 79 my ($data, $base) = @_;
186  
187 79 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 29 50 79
188 29 $self->{parser}->base_uri($base);
189 29 $self->{base} = $base;
190 }
191  
192 79 ▶ if (!ref($data)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $data) { } 1 78 79
elsif (UNIVERSAL::isa($data, 'GLOB')) { } 2 76 78
elsif (ref $data eq 'SCALAR') { } 72 4 76
193 1 ▶ if (@_ == 2 && !defined $base) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2 and not defined $base) 1 0 1
Condition33%1/3
@_ == 2 and not defined $base
!ll&&!rl&&r
001
MC/DC0%0/2
@_ == 2 and not defined $base
@_ == 2 not defined $base
Truth table33%1/3
A and not(B)
A= @_ == 2B= not defined $base
ABresult
0X0
100
111
194 1 $self->{parser}->base_uri($data);
195 1 $self->{base} = $data;
196 }
197 1 $data = $parser->parse_file($data);
198 } elsif (UNIVERSAL::isa($data, 'GLOB')) {
199 2 $data = $parser->parse_fh($data, $base);
200 } elsif (ref($data) eq 'SCALAR') {
201 72 $data = $parser->parse_string($$data, $base);
202 }
203 79 ▶ die "Not an XML::LibXML DOM" unless UNIVERSAL::isa($data, 'XML::LibXML::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($data, "XML::LibXML::Document") 1 78 79
204  
205 78 return $data;
206 }
207  
208 18 my @mips = qw(type readonly required relevant constraint calculate p3ptype);
209 101 ▶sub processBinds {
Subroutine processBinds: called CC=8 SCAR=21.0
Pod undocumented
210 101 my XML::XForms::Validate $self = shift;
211 101 my $node = shift;
212 101 my $context = shift;
213 101 for my $anon ($_[0]) {
214 101 foreach my $b ($xpc->findnodes('./xf:bind', $node)) {
215 73 my $id = $b->getAttribute('id');
216 73 ▶ $id = ' '.($anon++) unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 51 22 73
217 73 ▶ next if $self->{binds}{$id} || !$b->getAttribute('nodeset');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"binds"}{$id} or not $b->getAttribute("nodeset") 0 73 73
Condition33%1/3
$self->{"binds"}{$id} or not $b->getAttribute("nodeset")
l!l&&r!l&&!r
0073
MC/DC0%0/2
$self->{"binds"}{$id} or not $b->getAttribute("nodeset")
$self->{"binds"}{$id} not $b->getAttribute("nodeset")
Truth table33%1/3
A or not(B)
A= $self->{"binds"}{$id}B= not $b->getAttribute("nodeset")
ABresult
1X1
011
000
218 73 my $ctx = [ @$context, $b->getAttribute('nodeset') ];
219 73 $self->{binds}{$id} = { nodeset => $ctx, id => $id, node => $b };
220 73 foreach my $a (@mips) {
221 511 ▶ $self->{binds}{$id}{$a} = $b->getAttribute($a) if $b->getAttribute($a);
Branch: 1 branch
BranchTrueFalseTotal
if $b->getAttribute($a) 71 440 511
222 }
223 73 $self->processBinds($b, $ctx, $anon);
224 }
225 }
226 }
227  
228 18 my %formControls = map {$_=>1} qw(input secret textarea output upload range submit select select1 setvalue);
229 238 ▶sub processRefs {
Subroutine processRefs: called CC=16 SCAR=27.8
Pod undocumented
230 238 my XML::XForms::Validate $self = shift;
231 238 my ($node, $context, $model, $default) = @_;
232  
233 238 foreach my $ui ($node->childNodes) {
234 599 ▶ next unless $ui->isa('XML::LibXML::Element');
Branch: 1 branch
BranchTrueFalseTotal
unless $ui->isa("XML::LibXML::Element") 323 276 599
235 276 my $ctx = $context;
236 276 my $newdefault = $default;
237  
238 276 ▶ if (($ui->namespaceURI||'') eq NSURI_XF) {
Branch: 1 branch
BranchTrueFalseTotal
if (($ui->namespaceURI || "") eq "http://www.w3.org/2002/xforms") 276 0 276
Condition50%1/2
$ui->namespaceURI || ''
l!l
2760
MC/DC0%0/1
$ui->namespaceURI || ''
$ui->namespaceURI
Truth table50%1/2
A
A= $ui->namespaceURI
Aresult
11
00
239 276 ▶ my $id = $ui->localName eq 'model'?($ui->getAttribute('id')||''):($ui->getAttribute('model')||$default);
Branch: 1 branch
BranchTrueFalseTotal
$ui->localName eq 'model' ? : 47 229 276
Condition80%4/5
$ui->getAttribute("id") or ""
l!l
470
$ui->getAttribute("model") or $default
l!l&&r!l&&!r
361912
MC/DC0%0/1
$ui->getAttribute("id") or ""
$ui->getAttribute("id")
MC/DC100%2/2
$ui->getAttribute("model") or $default
$ui->getAttribute("model") $default
Truth table50%1/2
A
A= $ui->getAttribute("id")
Aresult
11
00
Truth table100%3/3
A or B
A= $ui->getAttribute("model")B= $default
ABresult
1X1
011
000
240 276 ▶ next if $id ne $model || $ui->localName eq 'instance';
Branch: 1 branch
BranchTrueFalseTotal
if $id ne $model or $ui->localName eq "instance" 66 210 276
Condition100%3/3
$id ne $model or $ui->localName eq "instance"
l!l&&r!l&&!r
5016210
MC/DC100%2/2
$id ne $model or $ui->localName eq "instance"
$id ne $model $ui->localName eq "instance"
Truth table100%3/3
A or B
A= $id ne $modelB= $ui->localName eq "instance"
ABresult
1X1
011
000
241 210 $newdefault = $id;
242 210 my @expr;
243 210 ▶ if (my $b = $ui->getAttribute('bind')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $ui->getAttribute("bind")) 21 189 210
244 21 ▶ die "Invalid XForms document: referenced bind \"$b\" not found" unless exists $self->{binds}{$b};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binds"}{$b} 0 21 21
245 21 @expr = @{$self->{binds}{$b}{'nodeset'}}
246 }
247 210 ▶ $expr[0] ||= $ui->getAttribute('nodeset');
Condition100%3/3
$expr[0] ||= $ui->getAttribute("nodeset")
l!l&&r!l&&!r
2173116
MC/DC100%2/2
$expr[0] ||= $ui->getAttribute("nodeset")
$expr[0] $ui->getAttribute("nodeset")
Truth table100%3/3
A ||= B
A= $expr[0]B= $ui->getAttribute("nodeset")
ABresult
1X1
011
000
248 210 ▶ $expr[0] ||= $ui->getAttribute('ref');
Condition100%3/3
$expr[0] ||= $ui->getAttribute("ref")
l!l&&r!l&&!r
945957
MC/DC100%2/2
$expr[0] ||= $ui->getAttribute("ref")
$expr[0] $ui->getAttribute("ref")
Truth table100%3/3
A ||= B
A= $expr[0]B= $ui->getAttribute("ref")
ABresult
1X1
011
000
249  
250 210 ▶ if (defined $expr[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr[0]) 153 57 210
251 153 $ctx = [ @$context, @expr ];
252 153 ▶ push @{$self->{refs}}, $ctx if exists $formControls{$ui->localName};
Branch: 1 branch
BranchTrueFalseTotal
if exists $formControls{$ui->localName} 72 81 153
253 }
254 }
255 210 $self->processRefs($ui, $ctx, $model, $newdefault);
256 }
257 }
258  
259 18 ▶use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
260 1169 ▶sub findNodes {
Subroutine findNodes: called CC=3 SCAR=11.0
Pod undocumented
261 1169 my XML::XForms::Validate $self = shift;
262 1169 my ($expr, $context, $xpath) = @_;
263 1169 ▶ cluck("undef") if !$expr;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 0 1169 1169
264 1169 my @expr = @$expr;
265 1169 my $last = pop @expr;
266 1169 foreach my $e (@expr) {
267 87 ($context) = $xpath->findnodes($e, $context);
268 }
269 1169 my @nodes = $xpath->findnodes($last, $context);
270 1169 return @nodes;
271 }
272  
273 190 ▶sub findBoolean {
Subroutine findBoolean: called CC=2 SCAR=6.9
Pod undocumented
274 190 my XML::XForms::Validate $self = shift;
275 190 my ($expr, $context, $xpath) = @_;
276 190 ▶ return $xpath->find("boolean($expr)", $context) && 1;
Condition100%2/2
$xpath->find("boolean($expr)", $context) && 1
!ll
51139
MC/DC100%1/1
$xpath->find("boolean($expr)", $context) && 1
$xpath->find("boolean($expr)", $context)
Truth table100%2/2
A
A= $xpath->find("boolean($expr)", $context)
Aresult
00
11
277 }
278  
279 52 ▶sub getInput {
Subroutine getInput: called CC=14 SCAR=26.7
Pod undocumented
280 52 my XML::XForms::Validate $self = shift;
281 52 my ($input, $orig, $submission) = @_;
282  
283 52 my $dom = {};
284 52 foreach my $key (keys %{$orig}) {
285 55 ▶ $$dom{$key} ||= $self->{parser}->parse_string($$orig{$key}->toString())->documentElement();
Condition66%2/3
$dom->{$key} ||= $self->{"parser"}->parse_string($orig->{$key}->toString)->documentElement
l!l&&r!l&&!r
1540
MC/DC0%0/2
$dom->{$key} ||= $self->{"parser"}->parse_string($orig->{$key}->toString)->documentElement
$dom->{$key} $self->{"parser"}->parse_string($orig->{$key}->toString)->documentElement
Truth table66%2/3
A ||= B
A= $dom->{$key}B= $self->{"parser"}->parse_string($orig->{$key}->toString)->documentElement
ABresult
1X1
011
000
286 55 ▶ $$dom{''} = $$dom{$key} if $key ne '' && $$orig{$key} eq $$orig{''};
Branch: 1 branch
BranchTrueFalseTotal
if $key ne "" and $orig->{$key} eq $orig->{""} 3 52 55
Condition66%2/3
$key ne "" and $orig->{$key} eq $orig->{""}
!ll&&!rl&&r
5203
MC/DC50%1/2
$key ne "" and $orig->{$key} eq $orig->{""}
$key ne "" $orig->{$key} eq $orig->{""}
Truth table66%2/3
A and B
A= $key ne ""B= $orig->{$key} eq $orig->{""}
ABresult
0X0
100
111
287 }
288  
289 0 ▶ my $ixpc = makeXPathContext(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
290 0 my ($id) = @_;
291 0 my $result = XML::LibXML::NodeList->new;
292 0 $result->push($$dom{$id});
293 0 return $result;
294 52 });
295  
296 52 my ($node) = $self->findNodes($submission, $$dom{''}, $ixpc);
297  
298 52 ▶ if (ref($input) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq "HASH") 1 51 52
299 1 my @values;
300 1 ▶ while (my ($key, $vals) = each %$input) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$input) 5 1 6
301 5 ▶ push @values, map { $key => $_ } (ref($vals)?@$vals:$vals);
Branch: 1 branch
BranchTrueFalseTotal
ref $vals ? : 2 3 5
302 }
303 1 $input = \@values;
304 }
305  
306 52 ▶ if (ref($input) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq 'ARRAY') { } 2 50 52
307 2 my %pos;
308 2 ▶ while (@$input) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$input) 12 2 14
309 12 my $key = shift @$input;
310 12 my $val;
311 0 ▶ if (ref($key)) { ($key, $val) = @$key; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key) { } 0 12 12
312 12 else { $val = shift @$input }
313 12 ($key) = $key =~ m/([a-zA-Z0-9:_-]*)/; # FIXME: QName.
314 12 my $pos = ++$pos{$key};
315 12 my ($node) = $xpc->findnodes(".//*[local-name() = '${key}' and not(*)][$pos]", $node);
316 12 $node->removeChildNodes();
317 12 $node->appendTextNode($val);
318 }
319 } else {
320 50 my $parent = $node->parentNode();
321 50 ▶ if (!$parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $parent) { } 47 3 50
322 47 $parent = $self->{parser}->parse_string($self->getDom($input)->documentElement()->toStringC14N());
323 47 foreach my $key (keys %$dom) {
324 50 ▶ $$dom{$key} = $parent->documentElement if ${$$dom{$key}->ownerDocument} eq ${$node->ownerDocument};
Branch: 1 branch
BranchTrueFalseTotal
if ${$dom->{$key}->ownerDocument;} eq ${$node->ownerDocument;} 50 0 50
325 }
326 47 $node = $parent;
327 } else {
328 3 my $new = $self->{parser}->parse_balanced_chunk($self->getDom($input)->documentElement()->toStringC14N())->firstChild;
329 3 $parent->replaceChild($new, $node);
330 3 $node = $new;
331 }
332 }
333  
334 52 return ($dom, $node);
335 }
336  
337 1533 ▶sub makeNodeName {
Subroutine makeNodeName: called CC=4 SCAR=13.9
Pod undocumented
338 1533 my ($node) = @_;
339 1533 my $name = $node->nodeName;
340 1533 ▶ $name = '<anon>' if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1533 1533
341 1533 ▶ return '' if $name =~ m/^xmlns/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^xmlns/ 148 1385 1533
342 1385 $name =~ s/^[^:]*://;
343 1385 my $ns = $node->namespaceURI();
344 1385 ▶ $ns = (defined $ns?"{$ns}":"");
Branch: 1 branch
BranchTrueFalseTotal
defined $ns ? : 16 1369 1385
345 1385 return $ns.$name;
346 }
347  
348 530 ▶sub checkTreeRecursive {
Subroutine checkTreeRecursive: called CC=17 SCAR=28.4
Pod undocumented
349 530 my XML::XForms::Validate $self = shift;
350 530 my ($new, $orig, $added) = @_;
351  
352 530 my $path = $new->nodePath;
353 530 my $ndoc = $new->ownerDocument;
354  
355 530 my $nname = makeNodeName($new);
356 530 my $oname = makeNodeName($orig);
357 530 ▶ return "Original node \"$oname\" doesn't match \"$nname\" ($path)"
Branch: 1 branch
BranchTrueFalseTotal
if $nname ne $oname 8 522 530
358 if $nname ne $oname;
359  
360 522 my @added;
361  
362 522 my %nattr = map { (makeNodeName($_) => $_) } $new->attributes;
363 522 my %oattr = map { (makeNodeName($_) => $_) } $orig->attributes;
364 522 delete $nattr{''};
365 522 delete $oattr{''};
366 522 foreach my $attr (keys %oattr) {
367 85 ▶ delete $nattr{$attr}, next if exists $nattr{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $nattr{$attr} 83 2 85
368 2 $new->setAttributeNS($oattr{$attr}->namespaceURI, $oattr{$attr}->nodeName, $oattr{$attr}->nodeValue);
369 2 my $clone = $new->getAttributeNodeNS($oattr{$attr}->namespaceURI, $oattr{$attr}->nodeName);
370 2 push @added, $clone;
371 }
372  
373 522 ▶ return "Additional attributes found: ".join(", ", keys %nattr)." ($path)"
Branch: 1 branch
BranchTrueFalseTotal
if %nattr 1 521 522
374 if %nattr;
375  
376 521 my @nelem = grep { $_->isa('XML::LibXML::Element') } $new->childNodes;
377 521 my @oelem = grep { $_->isa('XML::LibXML::Element') } $orig->childNodes;
378 521 my $firstmsg;
379 my $lastmsg;
380 521 ▶ while (@oelem) {
Branch: 1 branch
BranchTrueFalseTotal
if (@oelem) 478 519 997
381 478 ▶ last if !@nelem;
Branch: 1 branch
BranchTrueFalseTotal
unless @nelem 2 476 478
382 476 my $nnext = $nelem[0];
383 476 my $onext = shift @oelem;
384 476 my $msg = $self->checkTreeRecursive($nnext, $onext, \@added);
385 476 ▶ $firstmsg = undef, shift @nelem, next if !$msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg 466 10 476
386 10 my $clone = $self->{parser}->parse_balanced_chunk($onext->toString())->firstChild;
387 10 $new->insertBefore($clone, $nelem[0]);
388 10 ▶ $new->insertAfter($new->ownerDocument->createTextNode(''), $clone) if $onext->nextSibling->nodeType == XML_TEXT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
if $onext->nextSibling->nodeType == 3 10 0 10
389 10 push @added, $clone;
390 10 ▶ $firstmsg ||= $msg;
Condition66%2/3
$firstmsg ||= $msg
l!l&&r!l&&!r
550
MC/DC0%0/2
$firstmsg ||= $msg
$firstmsg $msg
Truth table66%2/3
A ||= B
A= $firstmsgB= $msg
ABresult
1X1
011
000
391 }
392  
393 521 ▶ push(@$added, @added), return undef if !@nelem && !@oelem;
Branch: 1 branch
BranchTrueFalseTotal
unless @nelem or @oelem 516 5 521
Condition100%3/3
@nelem or @oelem
l!l&&r!l&&!r
32516
MC/DC100%2/2
@nelem or @oelem
@nelem @oelem
Truth table100%3/3
A or B
A= @nelemB= @oelem
ABresult
1X1
011
000
394  
395 5 $_->parentNode->removeChild($_) foreach @added;
396 0 ▶ $firstmsg ||= "Additional child elements found: ".join(", ", map { $_->nodeName } @nelem)." ($path)" if @nelem;
Branch: 1 branch
BranchTrueFalseTotal
if @nelem 3 2 5
Condition50%1/2
$firstmsg ||= 'Additional child elements found: ' . join(", ", map({$_->nodeName;} @nelem)) . " ($path)"
l!l
30
MC/DC0%0/1
$firstmsg ||= 'Additional child elements found: ' . join(", ", map({$_->nodeName;} @nelem)) . " ($path)"
$firstmsg
Truth table50%1/2
A
A= $firstmsg
Aresult
11
00
397 5 ▶ $firstmsg ||= "Child elements missing: ".join(", ", map { $_->nodeName } @oelem)." ($path)" if @oelem;
Branch: 1 branch
BranchTrueFalseTotal
if @oelem 2 3 5
Condition50%1/2
$firstmsg ||= 'Child elements missing: ' . join(", ", map({$_->nodeName;} @oelem)) . " ($path)"
l!l
02
MC/DC0%0/1
$firstmsg ||= 'Child elements missing: ' . join(", ", map({$_->nodeName;} @oelem)) . " ($path)"
$firstmsg
Truth table50%1/2
A
A= $firstmsg
Aresult
11
00
398  
399 5 return $firstmsg;
400 }
401  
402 224 ▶sub hasParents {
Subroutine hasParents: called CC=3 SCAR=11.0
Pod undocumented
403 224 my ($child, $parents) = @_;
404 224 my $test = $child;
405 224 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$test = $test->parentNode and do { do { return 1 if exists $$parents{${$test;}} } } 540 8 548
406 764 ▶ return 1 if exists $$parents{${$test}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$parents{${$test;}} 216 548 764
407 } while ($test = $test->parentNode);
408 8 return 0;
409 }
410  
411 51 ▶sub checkTree {
Subroutine checkTree: called CC=13 SCAR=25.7
Pod undocumented
412 51 my XML::XForms::Validate $self = shift;
413 51 my ($new, $orig, $ixpc, $oxpc, $subtree) = @_;
414  
415 51 my $added = [];
416 51 foreach my $key (keys %$orig) {
417 54 my $result = $self->checkTreeRecursive($$new{$key}, $$orig{$key}, $added);
418 54 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 4 50 54
419 }
420  
421 47 $added = { map { ${$_} => $_ } @$added };
422 47 my %leftover = %$added;
423 47 foreach my $bind (values %{$self->{binds}}) {
424 280 ▶ next if !exists $$bind{relevant};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $bind->{"relevant"} 264 16 280
425 16 foreach my $node ($self->findNodes($$bind{nodeset}, $$new{''}, $ixpc)) {
426 16 ▶ next if $self->findBoolean($$bind{relevant}, $node, $ixpc);
Branch: 1 branch
BranchTrueFalseTotal
if $self->findBoolean($bind->{"relevant"}, $node, $ixpc) 11 5 16
427 5 my $deleted = delete $leftover{${$node}};
428 5 ▶ next if hasParents($node, $added) || !hasParents($node, $subtree);
Branch: 1 branch
BranchTrueFalseTotal
if hasParents($node, $added) or not hasParents($node, $subtree) 3 2 5
Condition66%2/3
hasParents($node, $added) or not hasParents($node, $subtree)
l!l&&r!l&&!r
302
MC/DC50%1/2
hasParents($node, $added) or not hasParents($node, $subtree)
hasParents($node, $added) not hasParents($node, $subtree)
Truth table66%2/3
A or not(B)
A= hasParents($node, $added)B= not hasParents($node, $subtree)
ABresult
1X1
011
000
429 2 ▶ return "Submission contains non-relevant node: ".$node->nodePath if !$deleted;
Branch: 1 branch
BranchTrueFalseTotal
unless $deleted 2 0 2
430 }
431 }
432  
433 45 foreach my $rest (values %leftover) {
434 2 delete $$added{${$rest}};
435 0 ▶ delete $leftover{${$rest}} if hasParents($rest, $added);
Branch: 1 branch
BranchTrueFalseTotal
if hasParents($rest, $added) 0 2 2
436 2 $$added{${$rest}} = $rest;
437 }
438 45 ▶ return "Missing relevant nodes: ".join(", ", map { $_->nodePath } values %leftover) if %leftover;
Branch: 1 branch
BranchTrueFalseTotal
if %leftover 2 43 45
439  
440 43 return undef;
441 }
442  
443 454 ▶sub checkReadonlyRecursive {
Subroutine checkReadonlyRecursive: called CC=19 SCAR=29.7
Pod undocumented
444 454 my XML::XForms::Validate $self = shift;
445 454 my ($new, $orig, $nrw, $orw) = @_;
446  
447 454 my %nattr = map { (makeNodeName($_) => $_) } $new->attributes;
448 454 my %oattr = map { (makeNodeName($_) => $_) } $orig->attributes;
449 454 delete $nattr{''};
450 454 delete $oattr{''};
451 454 foreach my $attr (keys %oattr) {
452 78 ▶ next if exists $$nrw{${$nattr{$attr}}} || exists $$orw{${$oattr{$attr}}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$nrw{${$nattr{$attr};}} or exists $$orw{${$oattr{$attr};}} 18 60 78
Condition66%2/3
exists $$nrw{${$nattr{$attr};}} or exists $$orw{${$oattr{$attr};}}
l!l&&r!l&&!r
18060
MC/DC50%1/2
exists $$nrw{${$nattr{$attr};}} or exists $$orw{${$oattr{$attr};}}
exists $$nrw{${$nattr{$attr};}} exists $$orw{${$oattr{$attr};}}
Truth table66%2/3
A or B
A= exists $$nrw{${$nattr{$attr};}}B= exists $$orw{${$oattr{$attr};}}
ABresult
1X1
011
000
453 60 $nattr{$attr}->setValue($oattr{$attr}->getValue());
454 }
455  
456 454 my @nelem = grep { $_->isa('XML::LibXML::Element') } $new->childNodes;
457 454 my @oelem = grep { $_->isa('XML::LibXML::Element') } $orig->childNodes;
458 454 ▶ while (@oelem) {
Branch: 1 branch
BranchTrueFalseTotal
if (@oelem) 408 453 861
459 408 my $nnext = shift @nelem;
460 408 my $onext = shift @oelem;
461 408 ▶ if (!exists $$nrw{${$nnext}} && !exists $$orw{${$onext}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}}) 153 255 408
Condition66%2/3
exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}}
l!l&&r!l&&!r
2550153
MC/DC50%1/2
exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}}
exists $$nrw{${$nnext;}} exists $$orw{${$onext;}}
Truth table66%2/3
A or B
A= exists $$nrw{${$nnext;}}B= exists $$orw{${$onext;}}
ABresult
1X1
011
000
462 153 my ($ntext) = $nnext->findnodes('./text()[1]');
463 153 my ($otext) = $onext->findnodes('./text()[1]');
464 153 ▶ $otext = ($otext?$otext->nodeValue:'');
Branch: 1 branch
BranchTrueFalseTotal
$otext ? : 143 10 153
465 153 ▶ if (!$ntext) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ntext) { } 10 143 153
466 10 $ntext = $nnext->appendText($otext);
467 } else {
468 143 $ntext->setData($otext);
469 }
470 }
471 408 my $result = $self->checkReadonlyRecursive($nnext, $onext, $nrw, $orw);
472 408 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 1 407 408
473 }
474  
475 453 @nelem = grep { $_->isa('XML::LibXML::Text') } $new->childNodes;
476 453 @oelem = grep { $_->isa('XML::LibXML::Text') } $orig->childNodes;
477 453 ▶ while (@oelem) {
Branch: 1 branch
BranchTrueFalseTotal
if (@oelem) 545 452 997
478 545 my $nnext = shift @nelem;
479 545 my $onext = shift @oelem;
480 545 ▶ if (!$nnext) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nnext) 1 544 545
481 1 my $val = $onext->nodeValue;
482 1 $val =~ s/^\s*|\s*$//g;
483 1 ▶ return "Text node missing for ".$onext->nodePath if length($val) && !exists $$orw{${onext}};
Branch: 1 branch
BranchTrueFalseTotal
if length $val and not exists $orw->{$onext} 1 0 1
Condition33%1/3
length $val and not exists $orw->{$onext}
!ll&&!rl&&r
001
MC/DC0%0/2
length $val and not exists $orw->{$onext}
length $val not exists $orw->{$onext}
Truth table33%1/3
A and not(B)
A= length $valB= not exists $orw->{$onext}
ABresult
0X0
100
111
484 0 ▶ $new->appendText('') if exists $$orw{${onext}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $orw->{$onext} 0 0 0
485 0 next;
486 }
487 544 ▶ next if exists $$nrw{${$nnext}} || exists $$orw{${$onext}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}} 89 455 544
Condition66%2/3
exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}}
l!l&&r!l&&!r
890455
MC/DC50%1/2
exists $$nrw{${$nnext;}} or exists $$orw{${$onext;}}
exists $$nrw{${$nnext;}} exists $$orw{${$onext;}}
Truth table66%2/3
A or B
A= exists $$nrw{${$nnext;}}B= exists $$orw{${$onext;}}
ABresult
1X1
011
000
488 455 $nnext->setData($onext->nodeValue);
489 }
490 452 foreach my $node (@nelem) {
491 147 ▶ $new->removeChild($node) unless exists $$nrw{${$node}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$nrw{${$node;}} 5 142 147
492 }
493  
494 452 return undef;
495 }
496  
497 654 ▶sub setRW {
Subroutine setRW: called CC=3 SCAR=11.0
Pod undocumented
498 654 my ($rw, $n) = @_;
499 654 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 636 18 654
500 636 $$rw{${$n}} = $n;
501 636 ($n) = $n->findnodes('./text()[1]');
502 636 ▶ $$rw{${$n}} = $n if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 332 304 636
503 }
504 }
505  
506 43 ▶sub checkReadonly {
Subroutine checkReadonly: called CC=18 SCAR=28.9
Pod undocumented
507 43 my XML::XForms::Validate $self = shift;
508 43 my ($new, $orig, $ixpc, $oxpc, $subtree) = @_;
509  
510 43 my %nrw;
511 my %orw;
512 43 foreach my $expr (@{$self->{refs}}) {
513 276 setRW(\%nrw, $self->findNodes($expr, $$new{''}, $ixpc));
514 276 setRW(\%orw, $self->findNodes($expr, $$orig{''}, $oxpc));
515 }
516  
517 43 foreach my $bind (values %{$self->{binds}}) {
518 273 my $ro = $$bind{readonly};
519 273 ▶ next if !defined $ro;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ro 203 70 273
520 70 foreach my $node ($self->findNodes($$bind{nodeset}, $$new{''}, $ixpc)) {
521 67 ▶ next if defined $ro && !$self->findBoolean($ro, $node, $ixpc);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ro and not $self->findBoolean($ro, $node, $ixpc) 13 54 67
Condition66%2/3
defined $ro and not $self->findBoolean($ro, $node, $ixpc)
!ll&&!rl&&r
05413
MC/DC50%1/2
defined $ro and not $self->findBoolean($ro, $node, $ixpc)
defined $ro not $self->findBoolean($ro, $node, $ixpc)
Truth table66%2/3
A and not(B)
A= defined $roB= not $self->findBoolean($ro, $node, $ixpc)
ABresult
0X0
100
111
522 54 delete $nrw{${$_}} foreach $node->findnodes('.|.//*|.//@*|.//text()');
523 }
524 70 foreach my $node ($self->findNodes($$bind{nodeset}, $$orig{''}, $oxpc)) {
525 67 ▶ next if defined $ro && !$self->findBoolean($ro, $node, $oxpc);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ro and not $self->findBoolean($ro, $node, $oxpc) 13 54 67
Condition66%2/3
defined $ro and not $self->findBoolean($ro, $node, $oxpc)
!ll&&!rl&&r
05413
MC/DC50%1/2
defined $ro and not $self->findBoolean($ro, $node, $oxpc)
defined $ro not $self->findBoolean($ro, $node, $oxpc)
Truth table66%2/3
A and not(B)
A= defined $roB= not $self->findBoolean($ro, $node, $oxpc)
ABresult
0X0
100
111
526 54 delete $orw{${$_}} foreach $node->findnodes('.|.//*|.//@*|.//text()');
527 }
528 }
529  
530 43 foreach my $bind (values %{$self->{binds}}) {
531 273 ▶ if (defined $$bind{calculate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bind->{"calculate"}) 47 226 273
532 47 setRW(\%nrw, $_) foreach ($self->findNodes($$bind{nodeset}, $$new{''}, $ixpc));
533 47 setRW(\%orw, $_) foreach ($self->findNodes($$bind{nodeset}, $$orig{''}, $oxpc));
534 }
535 }
536  
537 43 foreach my $key (keys %$orig) {
538 46 my $result = $self->checkReadonlyRecursive($$new{$key}, $$orig{$key}, \%nrw, \%orw);
539 46 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 1 45 46
540 }
541 }
542  
543 42 ▶sub checkBinds {
Subroutine checkBinds: called CC=28 SCAR=33.8
Pod undocumented
544 42 my XML::XForms::Validate $self = shift;
545 42 my ($new, $orig, $ixpc, $oxpc, $subtree) = @_;
546  
547 42 foreach my $bind (values %{$self->{binds}}) {
548 220 ▶ my ($prefix, $type) = ($$bind{type}||'') =~ m/^(?:([^:]*):)?(.*)$/;
Condition100%2/2
$bind->{'type'} || ''
l!l
67153
MC/DC100%1/1
$bind->{'type'} || ''
$bind->{'type'}
Truth table100%2/2
A
A= $bind->{'type'}
Aresult
11
00
549 220 ▶ $prefix ||= '';
Condition100%2/2
$prefix ||= ""
l!l
67153
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
550 220 my $calc = $$bind{calculate};
551 220 my $constraint = $$bind{constraint};
552 220 my $required = $$bind{required};
553 220 my $relevant = $$bind{relevant};
554 220 ▶ next unless defined $type || defined $calc || defined $constraint || defined $required;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type or defined $calc or defined $constraint or defined $required 0 220 220
Condition33%3/9
defined $type or defined $calc or defined $constraint or defined $required
l!l&&r!l&&!r
22000
defined $type or defined $calc or defined $constraint
l!l&&r!l&&!r
22000
defined $type or defined $calc
l!l&&r!l&&!r
22000
MC/DC0%0/4
defined $type or defined $calc or defined $constraint or defined $required
defined $type defined $calc defined $constraint defined $required
Truth table20%1/5
A or B or C or D
A= defined $typeB= defined $calcC= defined $constraintD= defined $required
ABCDresult
1XXX1
01XX1
001X1
00011
00000
555  
556 220 foreach my $node ($self->findNodes($$bind{nodeset}, $$new{''}, $ixpc)) {
557 215 ▶ next if !hasParents($node, $subtree) || (defined $relevant && !$self->findBoolean($relevant, $node, $ixpc));
Branch: 1 branch
BranchTrueFalseTotal
if not hasParents($node, $subtree) or defined $relevant and not $self->findBoolean($relevant, $node, $ixpc) 6 209 215
Condition100%6/6
not hasParents($node, $subtree) or defined $relevant and not $self->findBoolean($relevant, $node, $ixpc)
l!l&&r!l&&!r
42209
defined $relevant and not $self->findBoolean($relevant, $node, $ixpc)
!ll&&!rl&&r
20362
MC/DC100%3/3
not hasParents($node, $subtree) or defined $relevant and not $self->findBoolean($relevant, $node, $ixpc)
not hasParents($node, $subtree) defined $relevant not $self->findBoolean($relevant, $node, $ixpc)
Truth table100%4/4
not(A) or B and not(C)
A= not hasParents($node, $subtree)B= defined $relevantC= not $self->findBoolean($relevant, $node, $ixpc)
ABCresult
1XX1
0111
00X0
0100
558  
559 209 ▶ my $val = ($node->isa('XML::LibXML::Element')?$node->findvalue('./text()[1]'):$node->nodeValue);
Branch: 1 branch
BranchTrueFalseTotal
$node->isa('XML::LibXML::Element') ? : 176 33 209
560 209 my $path = $node->nodePath;
561  
562 209 ▶ return "Value required for $path" if defined $required
Branch: 1 branch
BranchTrueFalseTotal
if defined $required and $self->findBoolean($required, $node, $ixpc) and not length $val 3 206 209
Condition100%6/6
defined $required and $self->findBoolean($required, $node, $ixpc) and not length $val
!ll&&!rl&&r
20153
defined $required and $self->findBoolean($required, $node, $ixpc)
!ll&&!rl&&r
185168
MC/DC100%3/3
defined $required and $self->findBoolean($required, $node, $ixpc) and not length $val
defined $required $self->findBoolean($required, $node, $ixpc) not length $val
Truth table100%4/4
A and B and not(C)
A= defined $requiredB= $self->findBoolean($required, $node, $ixpc)C= not length $val
ABCresult
0XX0
10X0
1100
1111
563 && $self->findBoolean($required, $node, $ixpc) && !length($val);
564 206 ▶ return "Constraint error for $path ($constraint)" if defined $constraint
Branch: 1 branch
BranchTrueFalseTotal
if defined $constraint and not $self->findBoolean($constraint, $node, $ixpc) 2 204 206
Condition100%3/3
defined $constraint and not $self->findBoolean($constraint, $node, $ixpc)
!ll&&!rl&&r
19862
MC/DC100%2/2
defined $constraint and not $self->findBoolean($constraint, $node, $ixpc)
defined $constraint not $self->findBoolean($constraint, $node, $ixpc)
Truth table100%3/3
A and not(B)
A= defined $constraintB= not $self->findBoolean($constraint, $node, $ixpc)
ABresult
0X0
100
111
565 && !$self->findBoolean($constraint, $node, $ixpc);
566 204 ▶ return "Calculation mismatch for $path ($calc): expected \"".$ixpc->findvalue($calc, $node)."\", found \"$val\"" if defined $calc
Branch: 1 branch
BranchTrueFalseTotal
if defined $calc and $ixpc->findvalue($calc, $node) ne $val 2 202 204
Condition100%3/3
defined $calc and $ixpc->findvalue($calc, $node) ne $val
!ll&&!rl&&r
160422
MC/DC100%2/2
defined $calc and $ixpc->findvalue($calc, $node) ne $val
defined $calc $ixpc->findvalue($calc, $node) ne $val
Truth table100%3/3
A and B
A= defined $calcB= $ixpc->findvalue($calc, $node) ne $val
ABresult
0X0
100
111
567 && $ixpc->findvalue($calc, $node) ne $val;
568  
569 202 ▶ next unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 138 64 202
570 # FIXME: really needs switch to libxm
571 64 ▶ my $nsuri = $$bind{node}->lookupNamespaceURI($prefix) || '';
Condition50%1/2
$bind->{'node'}->lookupNamespaceURI($prefix) || ''
l!l
640
MC/DC0%0/1
$bind->{'node'}->lookupNamespaceURI($prefix) || ''
$bind->{'node'}->lookupNamespaceURI($prefix)
Truth table50%1/2
A
A= $bind->{'node'}->lookupNamespaceURI($prefix)
Aresult
11
00
572 64 my $class;
573 64 ▶ $class = XML::Schema::Type::Simple->builtin($type) if $nsuri eq NSURI_XSD || $nsuri eq NSURI_XS;
Branch: 1 branch
BranchTrueFalseTotal
if $nsuri eq "http://www.w3.org/2001/XMLSchema-datatypes" or $nsuri eq "http://www.w3.org/2001/XMLSchema" 38 26 64
Condition66%2/3
$nsuri eq "http://www.w3.org/2001/XMLSchema-datatypes" or $nsuri eq "http://www.w3.org/2001/XMLSchema"
l!l&&r!l&&!r
38026
MC/DC50%1/2
$nsuri eq "http://www.w3.org/2001/XMLSchema-datatypes" or $nsuri eq "http://www.w3.org/2001/XMLSchema"
$nsuri eq "http://www.w3.org/2001/XMLSchema-datatypes" $nsuri eq "http://www.w3.org/2001/XMLSchema"
Truth table66%2/3
A or B
A= $nsuri eq "http://www.w3.org/2001/XMLSchema-datatypes"B= $nsuri eq "http://www.w3.org/2001/XMLSchema"
ABresult
1X1
011
000
574 64 ▶ $class = "XML::XForms::Validate::Type::$type" if $nsuri eq NSURI_XF;
Branch: 1 branch
BranchTrueFalseTotal
if $nsuri eq "http://www.w3.org/2002/xforms" 26 38 64
575 64 my $const = UNIVERSAL::can($class, 'new');
576 64 ▶ return "Type $prefix:$type unsupported for $path" if !defined $const;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $const 0 64 64
577 64 my $obj = $const->($class);
578 64 ▶ return "Could not create object for $path ($type)" if !$obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 64 64
579 64 ▶ return "Type mismatch for $path ($type)"
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->instance($val) 9 55 64
580 if !$obj->instance($val);
581 }
582 }
583  
584 26 return undef;
585 }
586  
587 26 ▶sub checkSchema {
Subroutine checkSchema: called CC=3 SCAR=11.0
Pod undocumented
588 26 my XML::XForms::Validate $self = shift;
589 26 my ($new) = @_;
590  
591 26 foreach my $id (keys %{$self->{schemas}}) {
592 2 eval { $self->{schemas}{$id}->validate($$new{$id}->ownerDocument) };
593 2 ▶ return "Schema validation failed for instance \"$id\": $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
594 }
595 25 return undef;
596 }
597  
598 52 ▶sub validate {
Subroutine validate: called CC=18 SCAR=32.6
Pod documented
599 52 my XML::XForms::Validate $self;
600 52 ▶ $self = shift if UNIVERSAL::isa($_[0], 'XML::XForms::Validate');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "XML::XForms::Validate") 52 0 52
601 52 my %options = @_;
602 52 ▶ if (!$self) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self) 0 52 52
603 0 $self = new XML::XForms::Validate(xforms => $options{xforms}, model => $options{model}, base => $options{base});
604 }
605  
606 52 my $model = $self->{model};
607  
608 52 my $orig = { %{$self->{instances}} };
609  
610 52 ▶ if ($options{instance}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"instance"}) 0 52 52
611 0 ▶ $options{instance} = { '' => $options{instance} } if ref($options{instance}) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $options{"instance"} ne "HASH" 0 0 0
612 0 foreach my $key (keys %{$options{instance}}) {
613 0 my $replaced = $$orig{$key};
614 0 $$orig{$key} = $self->getDom($options{instance}{$key});
615 0 ▶ $$orig{''} = $$orig{$key} if $$orig{''} eq $replaced;
Branch: 1 branch
BranchTrueFalseTotal
if $orig->{""} eq $replaced 0 0 0
616 }
617 }
618  
619 52 ▶ $options{submission} = '' unless defined $options{submission};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"submission"} 49 3 52
620 52 my $subref = $self->{submissions}{$options{submission}}{'ref'};
621  
622 52 my ($new, $subnode) = $self->getInput($options{input}, $orig, $subref);
623  
624 20 ▶ my $oxpc = makeXPathContext(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
625 20 my ($id) = @_;
626 20 my $result = XML::LibXML::NodeList->new;
627 20 $result->push($$orig{$id});
628 20 return $result;
629 52 });
630 29 ▶ my $ixpc = makeXPathContext(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
631 29 my ($id) = @_;
632 29 my $result = XML::LibXML::NodeList->new;
633 29 $result->push($$new{$id});
634 29 return $result;
635 52 });
636  
637 52 my ($newsub) = $self->findNodes($subref, $$new{''}, $ixpc);
638 return "Submission does not match subtree reference (@$subref)"
639 52 ▶ if !$newsub || ${$newsub} ne ${$subnode};
Branch: 1 branch
BranchTrueFalseTotal
if not $newsub or ${$newsub;} ne ${$subnode;} 1 51 52
Condition66%2/3
not $newsub or ${$newsub;} ne ${$subnode;}
l!l&&r!l&&!r
1051
MC/DC50%1/2
not $newsub or ${$newsub;} ne ${$subnode;}
not $newsub ${$newsub;} ne ${$subnode;}
Truth table66%2/3
not(A) or B
A= not $newsubB= ${$newsub;} ne ${$subnode;}
ABresult
1X1
011
000
640  
641 51 ▶ if ($options{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"schema"}) 0 51 51
642 0 eval { XML::LibXML::Schema->new(location => $options{schema})->validate($subnode) };
643 0 ▶ return "Schema validation failed: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
644 0 return $new;
645 }
646  
647 51 my $subtree = { ${$subnode} => $subnode };
648 51 my $result = $self->checkTree($new, $orig, $ixpc, $oxpc, $subtree);
649 51 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 8 43 51
650 43 ($newsub) = $self->findNodes($subref, $$new{''}, $ixpc);
651 return "Submission does not match subtree reference (@$subref) after relevancy processing"
652 43 ▶ if !$newsub || ${$newsub} ne ${$subnode};
Branch: 1 branch
BranchTrueFalseTotal
if not $newsub or ${$newsub;} ne ${$subnode;} 0 43 43
Condition33%1/3
not $newsub or ${$newsub;} ne ${$subnode;}
l!l&&r!l&&!r
0043
MC/DC0%0/2
not $newsub or ${$newsub;} ne ${$subnode;}
not $newsub ${$newsub;} ne ${$subnode;}
Truth table33%1/3
not(A) or B
A= not $newsubB= ${$newsub;} ne ${$subnode;}
ABresult
1X1
011
000
653  
654 43 $result = $self->checkReadonly($new, $orig, $ixpc, $oxpc, $subtree);
655 43 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 1 42 43
656  
657 42 $result = $self->checkBinds($new, $orig, $ixpc, $oxpc, $subtree);
658 42 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 16 26 42
659  
660 26 $result = $self->checkSchema($new);
661 26 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 1 25 26
662  
663 25 return $new;
664 }
665  
666 # XPath Extensions
667 # These use an internal XPathContext for calculations to make sure XPath
668 # semantics are obeyed, especially regarding type conversion.
669  
670 156 ▶sub makeXPathContext {
Subroutine makeXPathContext: called CC=1 SCAR=0.0
Pod undocumented
671 156 my ($instancefunc) = @_;
672 156 my $xpc = new XML::LibXML::XPathContext;
673 156 $xpc->registerNs('xf', NSURI_XF); # FIXME: must be done on a per-evaluation basis instead
674 156 $xpc->registerFunction('instance', $instancefunc);
675 156 $xpc->registerFunction('boolean-from-string', \&XPath_booleanFromString);
676 156 $xpc->registerFunction('if', \&XPath_if);
677 156 $xpc->registerFunction('avg', \&XPath_avg);
678 156 $xpc->registerFunction('min', \&XPath_min);
679 156 $xpc->registerFunction('max', \&XPath_max);
680 156 $xpc->registerFunction('count-non-empty', \&XPath_countNonEmpty);
681 156 $xpc->registerFunction('index', \&XPath_index);
682 156 $xpc->registerFunction('property', \&XPath_property);
683 156 $xpc->registerFunction('now', \&XPath_now);
684 156 $xpc->registerFunction('days-from-date', \&XPath_daysFromDate);
685 156 $xpc->registerFunction('seconds-from-dateTime', \&XPath_secondsFromDateTime);
686 156 $xpc->registerFunction('seconds', \&XPath_seconds);
687 156 $xpc->registerFunction('months', \&XPath_months);
688 156 return $xpc;
689 }
690  
691 2 ▶sub XPath_booleanFromString {
Subroutine XPath_booleanFromString: called CC=5 SCAR=17.1
Pod undocumented
692 2 my ($str) = @_;
693 2 my $xpc = new XML::LibXML::XPathContext;
694 2 ▶ $xpc->registerVarLookupFunc(sub { return $str }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
695 2 $str = $xpc->findvalue('string($str)', $doc);
696 2 ▶ return XML::LibXML::Boolean->True if (lc($str) eq 'true' || $str eq '1');
Branch: 1 branch
BranchTrueFalseTotal
if lc $str eq "true" or $str eq 1 1 1 2
Condition66%2/3
lc $str eq "true" or $str eq 1
l!l&&r!l&&!r
011
MC/DC50%1/2
lc $str eq "true" or $str eq 1
lc $str eq "true" $str eq 1
Truth table66%2/3
A or B
A= lc $str eq "true"B= $str eq 1
ABresult
1X1
011
000
697 1 ▶ return XML::LibXML::Boolean->False if (lc($str) eq 'false' || $str eq '0');
Branch: 1 branch
BranchTrueFalseTotal
if lc $str eq "false" or $str eq 0 1 0 1
Condition33%1/3
lc $str eq "false" or $str eq 0
l!l&&r!l&&!r
100
MC/DC0%0/2
lc $str eq "false" or $str eq 0
lc $str eq "false" $str eq 0
Truth table33%1/3
A or B
A= lc $str eq "false"B= $str eq 0
ABresult
1X1
011
000
698 0 die "Invalid boolean string value: $str";
699 }
700  
701 2 ▶sub XPath_if {
Subroutine XPath_if: called CC=2 SCAR=6.9
Pod undocumented
702 2 my ($bool, $true, $false) = @_;
703 2 my $xpc = new XML::LibXML::XPathContext;
704 2 ▶ $xpc->registerVarLookupFunc(sub { return $bool }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
705 2 $bool = $xpc->findvalue('boolean($bool)', $doc);
706 2 ▶ return ($bool eq 'true'?$true:$false);
Branch: 1 branch
BranchTrueFalseTotal
$bool eq 'true' ? : 1 1 2
707 }
708  
709 1 ▶sub XPath_avg {
Subroutine XPath_avg: called CC=1 SCAR=0.0
Pod undocumented
710 1 my ($nodeset) = @_;
711  
712 1 my $xpc = new XML::LibXML::XPathContext;
713 1 ▶ $xpc->registerVarLookupFunc(sub { return $nodeset }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
714 1 return $xpc->find('sum($x) div count($x)', $doc);
715 }
716  
717 1 ▶sub XPath_min {
Subroutine XPath_min: called CC=4 SCAR=13.9
Pod undocumented
718 1 my ($nodeset) = @_;
719 1 ▶ return new XML::LibXML::Number('NaN') if (!$nodeset->size());
Branch: 1 branch
BranchTrueFalseTotal
unless $nodeset->size 0 1 1
720 1 my $min = $nodeset->shift;
721 1 my $cur = $min;
722  
723 1 my $xpc = new XML::LibXML::XPathContext;
724 1 ▶ $xpc->registerVarLookupFunc(sub { return $min }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
725 1 ▶ while ($nodeset->size()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodeset->size) 2 1 3
726 2 $cur = $nodeset->shift;
727 2 ▶ $min = $cur if $xpc->findvalue('. < $min', $cur) eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $xpc->findvalue(". < \$min", $cur) eq "true" 0 2 2
728 }
729  
730 1 return $min;
731 }
732  
733 1 ▶sub XPath_max {
Subroutine XPath_max: called CC=4 SCAR=13.9
Pod undocumented
734 1 my ($nodeset) = @_;
735 1 ▶ return new XML::LibXML::Number('NaN') if (!$nodeset->size());
Branch: 1 branch
BranchTrueFalseTotal
unless $nodeset->size 0 1 1
736 1 my $max = $nodeset->shift;
737 1 my $cur = $max;
738  
739 1 my $xpc = new XML::LibXML::XPathContext;
740 1 ▶ $xpc->registerVarLookupFunc(sub { return $max }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
741 1 ▶ while ($nodeset->size()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodeset->size) 2 1 3
742 2 $cur = $nodeset->shift;
743 2 ▶ $max = $cur if $xpc->findvalue('. > $max', $cur) eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $xpc->findvalue(". > \$max", $cur) eq "true" 2 0 2
744 }
745  
746 1 return $max;
747 }
748  
749 1 ▶sub XPath_countNonEmpty {
Subroutine XPath_countNonEmpty: called CC=3 SCAR=11.0
Pod undocumented
750 1 my ($nodeset) = @_;
751 1 my $cur;
752 1 my $result = 0;
753  
754 1 my $xpc = new XML::LibXML::XPathContext;
755 1 ▶ while ($nodeset->size()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodeset->size) 3 1 4
756 3 $cur = $nodeset->shift;
757 3 ▶ $result++ if $xpc->findvalue('string-length(.)', $cur) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $xpc->findvalue("string-length(.)", $cur) > 0 2 1 3
758 }
759  
760 1 return new XML::LibXML::Number($result);
761 }
762  
763 0 ▶sub XPath_index {
Subroutine XPath_index: not called CC=1 SCAR=6.9
Pod undocumented
764 # Doesn't apply to validation.
765 0 die "index() not supported.";
766 }
767  
768 1 ▶sub XPath_property {
Subroutine XPath_property: called CC=3 SCAR=11.4
Pod undocumented
769 1 my ($str) = @_;
770 1 my $xpc = new XML::LibXML::XPathContext;
771 1 ▶ $xpc->registerVarLookupFunc(sub { return $str }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
772 1 $str = $xpc->findvalue('string($str)', $doc);
773 1 ▶ return new XML::LibXML::Literal('1.0') if ($str eq 'version');
Branch: 1 branch
BranchTrueFalseTotal
if $str eq "version" 0 1 1
774 1 ▶ return new XML::LibXML::Literal('full') if ($str eq 'conformance-level');
Branch: 1 branch
BranchTrueFalseTotal
if $str eq "conformance-level" 1 0 1
775 0 return new XML::LibXML::Literal('');
776 }
777  
778 0 ▶sub XPath_now {
Subroutine XPath_now: not called CC=1 SCAR=6.9
Pod undocumented
779 0 my $now = localtime;
780 0 my $off = $now->tzoffset;
781 0 my $time = $now->datetime().sprintf('%+03d:%02d', int($off->hours), abs($off->minutes)%60);
782 0 return new XML::LibXML::Literal($time);
783 }
784  
785 2 ▶sub XPath_daysFromDate {
Subroutine XPath_daysFromDate: called CC=1 SCAR=0.0
Pod undocumented
786 2 my ($day) = @_;
787 2 my $xpc = new XML::LibXML::XPathContext;
788 2 ▶ $xpc->registerVarLookupFunc(sub { return $day }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
789 2 $day = $xpc->findvalue('string($day)', $doc);
790 2 $day =~ s/T.*//;
791 2 my $time = Time::Piece->strptime($day, "%Y-%m-%d")->epoch / ONE_DAY;
792 2 return new XML::LibXML::Number($time);
793 }
794  
795 2 ▶sub XPath_secondsFromDateTime {
Subroutine XPath_secondsFromDateTime: called CC=4 SCAR=14.7
Pod undocumented
796 2 my ($date) = @_;
797 2 my $xpc = new XML::LibXML::XPathContext;
798 2 ▶ $xpc->registerVarLookupFunc(sub { return $date }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
799 2 $date = $xpc->findvalue('string($date)', $doc);
800 2 my ($day, $sign, $h, $m) = $date =~ m/^(.*?)(?:\.[0-9]*)?(?:Z|([+-])([0-9]{2}):([0-9]{2}))?$/;
801 2 my $time = Time::Piece->strptime($day, "%Y-%m-%dT%H:%M:%S")->epoch;
802 2 ▶ $sign ||= '';
Condition50%1/2
$sign ||= ""
l!l
02
MC/DC0%0/1
$sign ||= ""
$sign
Truth table50%1/2
A
A= $sign
Aresult
11
00
803 2 ▶ if ($sign eq '+') {
Branch: 2 branches
BranchTrueFalseTotal
if ($sign eq '+') { } 0 2 2
elsif ($sign eq '-') { } 0 2 2
804 0 $time -= $h*60+$m;
805 } elsif ($sign eq '-') {
806 0 $time += $h*60+$m;
807 }
808 2 return new XML::LibXML::Number($time);
809 }
810  
811 1 ▶sub XPath_seconds {
Subroutine XPath_seconds: called CC=1 SCAR=0.0
Pod undocumented
812 1 my ($duration) = @_;
813 1 my $xpc = new XML::LibXML::XPathContext;
814 1 ▶ $xpc->registerVarLookupFunc(sub { return $duration }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
815 1 $duration = $xpc->findvalue('string($duration)', $doc);
816 1 my ($sign, $d, $h, $m, $s) = $duration =~ m/^([+-]?)P.*?(?:([0-9]+)D)?(?:T(?:([0-9]+)H)?(?:([0-9]+)M)?(?:([0-9.]+)S)?)?$/;
817 1 $sign .= 1;
818 1 return new XML::LibXML::Number(((($d*24+$h)*60+$m)*60+$s)*$sign);
819 }
820  
821 1 ▶sub XPath_months {
Subroutine XPath_months: called CC=1 SCAR=0.0
Pod undocumented
822 1 my ($duration) = @_;
823 1 my $xpc = new XML::LibXML::XPathContext;
824 1 ▶ $xpc->registerVarLookupFunc(sub { return $duration }, undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
825 1 $duration = $xpc->findvalue('string($duration)', $doc);
826 1 my ($sign, $y, $m) = $duration =~ m/^([+-]?)P(?:([0-9]+)Y)?(?:([0-9]+)M)?.*$/;
827 1 $sign .= 1;
828 1 return new XML::LibXML::Number(($y*12+$m)*$sign);
829 }
830  
831 package XML::Schema::Type::duration;
832 18 ▶use base qw( XML::Schema::Type::timeDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
833 # FIXME: hack for XML::Schema bug
834  
835 package XML::Schema::Type::dateTime;
836 18 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
837 18 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
838 18 @FACETS = (
839 period => { value => 'P10000Y', fixed => 1 },
840 duration => { value => 'P0Y', fixed => 1 },
841 );
842 # FIXME: hack for XML::Schema bug
843  
844 package XML::XForms::Validate::Type::listItem;
845 18 ▶use base qw( XML::Schema::Type::string );
Subroutine BEGIN: called CC=1 SCAR=0.0
846 18 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
847  
848 18 @FACETS = (
849 pattern => {
850 value => '^\S+$',
851 errmsg => 'value is not a valid listItem',
852 }
853 );
854  
855 package XML::XForms::Validate::Type::listItems;
856 18 ▶use base qw( XML::Schema::Type::string );
Subroutine BEGIN: called CC=1 SCAR=0.0
857 18 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
858 # FIXME: this is technically wrong, but sufficient for our purposes.
859  
860 18 @FACETS = (
861 pattern => {
862 value => '^((\S+\s+)*\S+)?$',
863 errmsg => 'value is not a valid listItem list',
864 }
865 );
866  
867 package XML::XForms::Validate::Type::dayTimeDuration;
868 18 ▶use base qw( XML::Schema::Type::duration );
Subroutine BEGIN: called CC=1 SCAR=0.0
869 18 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
870 # FIXME: no idea if this works as intended.
871  
872 18 @FACETS = (
873 duration => { value => 'P0Y0M', fixed => 1 },
874 );
875  
876 package XML::XForms::Validate::Type::yearMonthDuration;
877 18 ▶use base qw( XML::Schema::Type::duration );
Subroutine BEGIN: called CC=1 SCAR=0.0
878 18 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
879 # FIXME: no idea if this works as intended.
880  
881 18 @FACETS = (
882 duration => { value => 'P0DT0H0M0S', fixed => 1 },
883 );
884  
885  
886 18 1;
887 __END__
↑ Summary