PRANG/Graph/Element.pm

filter: Statementstmt 77.7% 126 / 162 Branchbran 66.6% 60 / 90 Conditioncond 60.6% 37 / 61 MC/DCmcdc 42.4% 14 / 33 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 68.5% 248 / 362 SCAR 52.5
CC
71
Cov
71%
output
110.6
accept
24.7
node_ok
18.0
CRAP 190.8
« PRANG/Graph/Meta/Element.pm ↑ Summary PRANG/Marshaller.pm »
1  
2 package PRANG::Graph::Element;
3 11 $PRANG::Graph::Element::VERSION = '0.19';
4 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 BEGIN {
11 11 ▶ class_type "XML::LibXML::Node";
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 class_type "XML::LibXML::Element";
13 }
14  
15 11 has 'xmlns' =>
16 is => "ro",
17 isa => "Str",
18 predicate => "has_xmlns",
19 ;
20  
21 11 has 'nodeName' =>
22 is => "ro",
23 isa => "Str",
24 required => 1,
25 ;
26  
27 11 has 'nodeClass' =>
28 is => "ro",
29 isa => "Str",
30 predicate => "has_nodeClass",
31 ;
32  
33 11 has 'nodeName_attr' =>
34 is => "rw",
35 isa => "Str",
36 predicate => "has_nodeName_attr",
37 ;
38  
39 11 has 'xmlns_attr' =>
40 is => "rw",
41 isa => "Str",
42 predicate => "has_xmlns_attr",
43 ;
44  
45 11 has 'attrName' =>
46 is => "ro",
47 isa => "Str",
48 required => 1,
49 ;
50  
51 11 has 'contents' =>
52 is => "rw",
53 isa => "PRANG::Graph::Node",
54 predicate => "has_contents",
55 ;
56  
57 sub node_ok {
58 1126 ▶ my $self = shift;
Subroutine node_ok: called CC=18 SCAR=28.9
Pod undocumented
59 1126 my ( $node, $ctx ) = pos_validated_list(
60 \@_,
61 { isa => 'XML::LibXML::Node' },
62 { isa => 'PRANG::Graph::Context' },
63 );
64
65 1126 ▶ return unless $node->nodeType == XML_ELEMENT_NODE;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->nodeType == 1 101 1025 1126
66 1025 my $got_xmlns;
67  
68 1025 ▶ if ($self->has_xmlns
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_xmlns or ($node->prefix || "") ne ($ctx->prefix || "")) 337 688 1025
Condition100%7/7
$self->has_xmlns or ($node->prefix || "") ne ($ctx->prefix || "")
l!l&&r!l&&!r
155182688
$node->prefix || ''
l!l
125745
$ctx->prefix || ''
l!l
213657
MC/DC100%2/2
$self->has_xmlns or ($node->prefix || "") ne ($ctx->prefix || "")
$self->has_xmlns $node->prefix
MC/DC100%1/1
$ctx->prefix || ''
$ctx->prefix
Truth table100%3/3
A or B
A= $self->has_xmlnsB= $node->prefix
ABresult
1X1
011
000
Truth table100%2/2
A
A= $ctx->prefix
Aresult
11
00
69 or
70 ($node->prefix||"") ne ($ctx->prefix||"")
71 )
72 337 ▶ { my $prefix = $node->prefix//"";
Condition100%2/2
$node->prefix // ""
l!l
163174
MC/DC100%1/1
$node->prefix // ""
$node->prefix
Truth table100%2/2
A
A= $node->prefix
Aresult
11
00
73 337 $got_xmlns = $ctx->xsi->{$prefix};
74 337 ▶ if ( !defined $got_xmlns ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $got_xmlns) 6 331 337
75 6 ▶ $got_xmlns = $node->getAttribute(
Branch: 1 branch
BranchTrueFalseTotal
length $prefix ? : 6 0 6
76 "xmlns".(length $prefix?":$prefix":"")
77 );
78 }
79 337 ▶ my $wanted_xmlns = ($self->xmlns||"");
Condition100%2/2
$self->xmlns || ''
l!l
155182
MC/DC100%1/1
$self->xmlns || ''
$self->xmlns
Truth table100%2/2
A
A= $self->xmlns
Aresult
11
00
80 337 ▶ if ($got_xmlns
Branch: 1 branch
BranchTrueFalseTotal
if ($got_xmlns and $wanted_xmlns ne "*" and $got_xmlns ne $wanted_xmlns) 77 260 337
Condition100%6/6
$got_xmlns and $wanted_xmlns ne "*" and $got_xmlns ne $wanted_xmlns
!ll&&!rl&&r
1926877
$got_xmlns and $wanted_xmlns ne "*"
!ll&&!rl&&r
17418145
MC/DC100%3/3
$got_xmlns and $wanted_xmlns ne "*" and $got_xmlns ne $wanted_xmlns
$got_xmlns $wanted_xmlns ne "*" $got_xmlns ne $wanted_xmlns
Truth table100%4/4
A and B and C
A= $got_xmlnsB= $wanted_xmlns ne "*"C= $got_xmlns ne $wanted_xmlns
ABCresult
0XX0
10X0
1100
1111
81 and $wanted_xmlns ne "*"
82 and
83 $got_xmlns ne $wanted_xmlns
84 )
85 77 { return;
86 }
87 }
88 948 my ($ret_nodeName, $ret_xmlns) = ("", "");
89 948 my $wanted_nodeName = $self->nodeName;
90 948 ▶ if ($wanted_nodeName ne "*"
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_nodeName ne "*" and $wanted_nodeName ne $node->localname) 299 649 948
Condition100%3/3
$wanted_nodeName ne "*" and $wanted_nodeName ne $node->localname
!ll&&!rl&&r
62587299
MC/DC100%2/2
$wanted_nodeName ne "*" and $wanted_nodeName ne $node->localname
$wanted_nodeName ne "*" $wanted_nodeName ne $node->localname
Truth table100%3/3
A and B
A= $wanted_nodeName ne "*"B= $wanted_nodeName ne $node->localname
ABresult
0X0
100
111
91 and $wanted_nodeName ne $node->localname
92 )
93 299 { return;
94 }
95 649 ▶ if ( $self->has_nodeName_attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_nodeName_attr) 74 575 649
96 74 $ret_nodeName = $node->localname;
97 }
98 649 ▶ if ( $self->has_xmlns_attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_xmlns_attr) 51 598 649
99 51 $ret_xmlns = $got_xmlns;
100 }
101 649 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 335 314 649
102 335 return ($ret_nodeName, $ret_xmlns);
103 }
104 else {
105 314 return $ret_nodeName;
106 }
107 }
108  
109 sub accept {
110 335 ▶ my $self = shift;
Subroutine accept: called CC=16 SCAR=32.1
Pod undocumented
111 335 my ( $node, $ctx, $lax ) = pos_validated_list(
112 \@_,
113 { isa => 'XML::LibXML::Node' },
114 { isa => 'PRANG::Graph::Context' },
115 { isa => 'Bool', optional => 1 },
116 );
117
118 335 my ($ret_nodeName, $xmlns) = $self->node_ok($node, $ctx);
119 335 ▶ if ( !defined $ret_nodeName ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret_nodeName) 0 335 335
120  
121 # ok, not right, so figure out what we did want, in
122 # the context of the incoming document.
123 0 ▶ my $wanted_xmlns = ($self->xmlns||"");
Condition0%0/2
$self->xmlns || ''
l!l
00
MC/DC0%0/1
$self->xmlns || ''
$self->xmlns
Truth table0%0/2
A
A= $self->xmlns
Aresult
11
00
124 0 my $wanted_prefix = $ctx->get_prefix($wanted_xmlns);
125  
126 0 my $nodeName = $self->nodeName;
127 0 ▶ if ( $wanted_prefix ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_prefix ne "") 0 0 0
128 0 $nodeName = "$wanted_prefix:$nodeName";
129 0 ▶ if ( $ctx->prefix_new($wanted_prefix) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->prefix_new($wanted_prefix)) 0 0 0
130 0 $nodeName .= " xmlns:$wanted_prefix="
131 ."\"$wanted_xmlns\"";
132 }
133 }
134 $ctx->exception(
135 0 "invalid element; expected '$nodeName'",
136 $node, 1,
137 );
138 }
139 335 ▶ undef($ret_nodeName) if !length($ret_nodeName);
Branch: 1 branch
BranchTrueFalseTotal
unless length $ret_nodeName 306 29 335
140 335 ▶ if ( $self->has_nodeClass ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_nodeClass) { } 173 162 335
141  
142 # general nested XML support
143 173 my $marshaller = $ctx->base->get($self->nodeClass);
144 173 ▶ my $value = (
Branch: 1 branch
BranchTrueFalseTotal
$marshaller ? : 173 0 173
145 $marshaller
146 ? $marshaller->marshall_in_element(
147 $node,
148 $ctx,
149 $lax,
150 )
151 : $node
152 );
153 155 $ctx->element_ok(1);
154 155 return ($self->attrName => $value, $ret_nodeName, $xmlns);
155 }
156 else {
157  
158 # XML data types
159 162 ▶ my $type = $self->has_contents
Branch: 1 branch
BranchTrueFalseTotal
$self->has_contents ? : 156 6 162
160 ?
161 "XML data"
162 : "presence-only";
163 162 ▶ if ($node->hasAttributes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->hasAttributes) 2 160 162
164 2 $ctx->exception(
165 "Superfluous attributes on $type node",
166 $node
167 );
168 }
169 160 ▶ if ( $self->has_contents ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_contents) { } 155 5 160
170  
171 # simple types, eg Int, Str
172 my (@childNodes) = grep {
173 155 ▶ !( $_->isa("XML::LibXML::Comment")
Condition33%2/6
$_->isa('XML::LibXML::Comment') || $_->isa('XML::LibXML::Text') && $_->data =~ /\A\s+\Z/
l!l&&r!l&&!r
0092
$_->isa("XML::LibXML::Text") and $_->data =~ /\A\s+\Z/
!ll&&!rl&&r
0920
MC/DC0%0/3
$_->isa('XML::LibXML::Comment') || $_->isa('XML::LibXML::Text') && $_->data =~ /\A\s+\Z/
$_->isa('XML::LibXML::Comment') $_->isa("XML::LibXML::Text") $_->data =~ /\A\s+\Z/
Truth table25%1/4
A || B and C
A= $_->isa('XML::LibXML::Comment')B= $_->isa("XML::LibXML::Text")C= $_->data =~ /\A\s+\Z/
ABCresult
1XX1
0111
00X0
0100
174 or
175 $_->isa("XML::LibXML::Text")
176 and $_->data =~ /\A\s+\Z/
177 )
178 } $node->childNodes;
179  
180 155 ▶ if ( @childNodes > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@childNodes > 1) 0 155 155
181  
182 # we could maybe merge CDATA nodes...
183 0 $ctx->exception(
184 "Too many child nodes for $type node",
185 $node,
186 );
187 }
188 155 my $value;
189 155 ▶ if ( !@childNodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @childNodes) { } 63 92 155
190 63 $value = "";
191 }
192 else {
193 92 (undef, $value) = $self->contents->accept(
194 $childNodes[0],
195 $ctx,
196 $lax,
197 );
198 }
199 155 $ctx->element_ok(1);
200 155 return ($self->attrName => $value, $ret_nodeName, $xmlns);
201 }
202 else {
203  
204 # boolean
205 5 ▶ if ( $node->hasChildNodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->hasChildNodes) 1 4 5
206 1 $ctx->exception(
207 "Superfluous child nodes on $type node",
208 $node,
209 );
210 }
211 4 $ctx->element_ok(1);
212 4 return ($self->attrName => 1, $ret_nodeName, $xmlns);
213 }
214 }
215 }
216  
217 sub complete {
218 15 ▶ my $self = shift;
Subroutine complete: called CC=1 SCAR=0.0
Pod undocumented
219 15 my ( $ctx ) = pos_validated_list(
220 \@_,
221 { isa => 'PRANG::Graph::Context' },
222 );
223
224 15 $ctx->element_ok;
225 }
226  
227 sub expected {
228 11 ▶ my $self = shift;
Subroutine expected: called CC=6 SCAR=25.8
Pod undocumented
229 11 my ( $ctx ) = pos_validated_list(
230 \@_,
231 { isa => 'PRANG::Graph::Context' },
232 );
233
234 11 my $prefix = "";
235 11 my $nodename = $self->nodeName;
236 11 ▶ if ( $self->has_xmlns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_xmlns) 0 11 11
237 0 ▶ my $xmlns = eval { $self->nodeClass->xmlns } ||
Condition0%0/3
eval { || $self->xmlns
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { $self->nodeClass->xmlns } } || $self->xmlns
eval { do { $self->nodeClass->xmlns } } $self->xmlns
Truth table0%0/3
A || B
A= eval { do { $self->nodeClass->xmlns } }B= $self->xmlns
ABresult
1X1
011
000
238 $self->xmlns;
239 0 ▶ if ( $prefix = $ctx->rxsi->{$xmlns} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix = $ctx->rxsi->{$xmlns}) { } 0 0 0
240 0 $prefix .= ":";
241 }
242 else {
243 0 $prefix = $ctx->get_prefix($xmlns);
244 0 $nodename .= " xmlns:$prefix='$xmlns'";
245 0 $prefix .= ":";
246 }
247 }
248 11 ▶ return "<$prefix$nodename".(
Branch: 2 branches
BranchTrueFalseTotal
$self->has_nodeClass ? : 4 7 11
$self->has_contents ? : 7 0 7
249 $self->has_nodeClass
250 ?"..."
251 :
252 $self->has_contents?"":"/"
253 )
254 .">";
255 }
256  
257 sub output {
258 152 ▶ my $self = shift;
Subroutine output: called CC=34 SCAR=47.1
Pod undocumented
259
260 # First 3 args positional, rest are named
261 # Because we're making 2 validation calls, we have to use different cache keys
262 152 my ( $item, $node, $ctx ) = pos_validated_list(
263 [@_[0..2]],
264 { isa => 'Object' },
265 { isa => 'XML::LibXML::Element' },
266 { isa => 'PRANG::Graph::Context' },
267 MX_PARAMS_VALIDATE_CACHE_KEY => 'element-output-positional',
268 );
269
270 152 my ( $value, $slot, $name, $xmlns ) = validated_list(
271 [@_[3..$#_]],
272 value => { isa => 'Item', optional => 1 },
273 slot => { isa => 'Int', optional => 1 },
274 name => { isa => 'Str', optional => 1 },
275 xmlns => { isa => 'Str', optional => 1 },
276 MX_PARAMS_VALIDATE_CACHE_KEY => 'element-output-named',
277 );
278
279
280 152 ▶ $value //= do {
Condition100%3/3
$value //= do {
l!l&&r!l&&!r
101501
MC/DC100%2/2
$value //= do { my $accessor = $self->attrName; $item->$accessor }
$value do { my $accessor = $self->attrName; $item->$accessor }
Truth table100%3/3
A //= B
A= $valueB= do { my $accessor = $self->attrName; $item->$accessor }
ABresult
1X1
011
000
281 51 my $accessor = $self->attrName;
282 51 $item->$accessor;
283 };
284 152 ▶ if ( ref $value and ref $value eq "ARRAY" and defined $slot ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and ref $value eq "ARRAY" and defined $slot) 0 152 152
Condition50%3/6
ref $value and ref $value eq "ARRAY" and defined $slot
!ll&&!rl&&r
15200
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
79730
MC/DC0%0/3
ref $value and ref $value eq "ARRAY" and defined $slot
ref $value ref $value eq "ARRAY" defined $slot
Truth table50%2/4
A and B and C
A= ref $valueB= ref $value eq "ARRAY"C= defined $slot
ABCresult
0XX0
10X0
1100
1111
285 0 $value = $value->[$slot];
286 }
287 152 ▶ $name //= do {
Condition66%2/3
$name //= do {
l!l&&r!l&&!r
371150
MC/DC0%0/2
$name //= do { if ($self->has_nodeName_attr) { my $attr = $self->nodeName_attr; $item->$attr; } else { $self->nodeName; } }
$name do { if ($self->has_nodeName_attr) { my $attr = $self->nodeName_attr; $item->$attr; } else { $self->nodeName; } }
Truth table66%2/3
A //= B
A= $nameB= do { if ($self->has_nodeName_attr) { my $attr = $self->nodeName_attr; $item->$attr; } else { $self->nodeName; } }
ABresult
1X1
011
000
288 115 ▶ if ( $self->has_nodeName_attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_nodeName_attr) { } 4 111 115
289 4 my $attr = $self->nodeName_attr;
290 4 $item->$attr;
291 }
292 else {
293 111 $self->nodeName;
294 }
295 };
296 152 ▶ $xmlns //= do {
Condition66%2/3
$xmlns //= do {
l!l&&r!l&&!r
121400
MC/DC0%0/2
$xmlns //= do { if ($self->has_xmlns_attr) { my $attr = $self->xmlns_attr; $item->$attr; } else { $self->xmlns // ""; } }
$xmlns do { if ($self->has_xmlns_attr) { my $attr = $self->xmlns_attr; $item->$attr; } else { $self->xmlns // ""; } }
Truth table66%2/3
A //= B
A= $xmlnsB= do { if ($self->has_xmlns_attr) { my $attr = $self->xmlns_attr; $item->$attr; } else { $self->xmlns // ""; } }
ABresult
1X1
011
000
297 140 ▶ if ( $self->has_xmlns_attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_xmlns_attr) { } 0 140 140
298 0 my $attr = $self->xmlns_attr;
299 0 $item->$attr;
300 }
301 else {
302 140 ▶ $self->xmlns // "";
Condition100%2/2
$self->xmlns // ""
l!l
6134
MC/DC100%1/1
$self->xmlns // ""
$self->xmlns
Truth table100%2/2
A
A= $self->xmlns
Aresult
11
00
303 }
304 };
305 152 ▶ if ( ref $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) 4 148 152
306 4 $name = $name->[$slot];
307 }
308 152 ▶ if ( ref $xmlns ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $xmlns) 0 152 152
309 0 $xmlns = $xmlns->[$slot];
310 }
311  
312 152 my $nn;
313 152 my $doc = $node->ownerDocument;
314 152 my $newctx;
315 152 ▶ if ( length $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $name) { } 152 0 152
316 152 my ($prefix, $new_prefix);
317 152 $ctx = $ctx->next_ctx( $xmlns, $name, $value );
318 152 $prefix = $ctx->prefix;
319 152 ▶ my $new_nodeName = ($prefix ? "$prefix:" : "") . $name;
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 35 117 152
320 152 $nn = $doc->createElement($new_nodeName);
321 152 ▶ if ( $ctx->prefix_new($prefix) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->prefix_new($prefix)) 11 141 152
322 11 ▶ $nn->setAttribute(
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 11 0 11
323 "xmlns".($prefix?":$prefix":""),
324 $xmlns,
325 );
326 }
327 152 $node->appendChild($nn);
328  
329 # now proceed with contents...
330 152 ▶ if ( my $class = $self->nodeClass ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $class = $self->nodeClass) { } 74 78 152
elsif ($self->has_contents and defined $value) { } 77 2 79
331 74 my $m;
332 74 ▶ if ( !defined $value ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $value) { } 1 73 74
elsif (eval { do { $value->isa($class) } }) { } 73 0 73
elsif (eval { do { $value->isa('XML::LibXML::Element') } }) { } 0 0 0
elsif (builtin::blessed($value)) { } 0 0 0
333 1 $ctx->exception("required element not set");
334 }
335 73 elsif ( eval { $value->isa($class) }) {
336 73 $m = $ctx->base->get($class);
337 }
338 0 elsif ( eval{$value->isa("XML::LibXML::Element")} ) {
339 0 ▶ if ($value->localname eq $nn->localname
Branch: 1 branch
BranchTrueFalseTotal
if ($value->localname eq $nn->localname and ($value->namespaceURI || '') eq ($xmlns || '')) { } 0 0 0
Condition0%0/7
$value->localname eq $nn->localname and ($value->namespaceURI || "") eq ($xmlns || "")
!ll&&!rl&&r
000
$value->namespaceURI || ''
l!l
00
$xmlns || ''
l!l
00
MC/DC0%0/2
$value->localname eq $nn->localname and ($value->namespaceURI || "") eq ($xmlns || "")
$value->localname eq $nn->localname $value->namespaceURI
MC/DC0%0/1
$xmlns || ''
$xmlns
Truth table0%0/3
A and B
A= $value->localname eq $nn->localnameB= $value->namespaceURI
ABresult
0X0
100
111
Truth table0%0/2
A
A= $xmlns
Aresult
11
00
340 and
341 ($value->namespaceURI||"") eq
342 ($xmlns||"")
343 )
344 0 { my $nn2 = $value->cloneNode(1);
345 0 $node->appendChild($nn2);
346 0 $node->removeChild($nn);
347 }
348 else {
349  
350 # it's just not safe to set
351 # the nodeName after the fact,
352 # so copy the children across.
353 0 for my $att ( $value->attributes ) {
354 0 ▶ next if $att->isa("XML::LibXML::Namespace");
Branch: 1 branch
BranchTrueFalseTotal
if $att->isa("XML::LibXML::Namespace") 0 0 0
355 0 $nn->setAttribute(
356 $att->localname,
357 $att->value,
358 );
359 }
360 0 for my $child ( $value->childNodes ) {
361 0 my $nn2 = $child->cloneNode(1);
362 0 $nn->appendChild($nn2);
363 }
364 }
365 0 $m = "ok";
366 }
367 elsif ( blessed $value ) {
368  
369 # this actually indicates a type
370 # error. currently it is required for
371 # the Whatever mapping.
372 0 $m = PRANG::Marshaller->get(ref $value);
373 }
374  
375 73 ▶ if ( $m and blessed $m ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($m and builtin::blessed($m)) { } 73 0 73
elsif ($m) { } 0 0 0
Condition33%1/3
$m and builtin::blessed($m)
!ll&&!rl&&r
0073
MC/DC0%0/2
$m and builtin::blessed($m)
$m builtin::blessed($m)
Truth table33%1/3
A and B
A= $mB= builtin::blessed($m)
ABresult
0X0
100
111
376 73 ▶ $ctx->exception(
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) 0 73 73
377 "tried to serialize unblessed value $value"
378 )
379 if !blessed $value;
380 73 $m->to_libxml($value, $nn, $ctx);
381 }
382 elsif ($m) {
383  
384 # allow value-based code above to drop through
385 }
386 else {
387 0 $ctx->exception("no marshaller for '$value'");
388 }
389 }
390 ▶ elsif ( $self->has_contents and defined $value ) {
Condition66%2/3
$self->has_contents and defined $value
!ll&&!rl&&r
1077
MC/DC50%1/2
$self->has_contents and defined $value
$self->has_contents defined $value
Truth table66%2/3
A and B
A= $self->has_contentsB= defined $value
ABresult
0X0
100
111
391 77 my $tn = $self->createTextNode($doc, $value);
392 77 $nn->appendChild($tn);
393 }
394 }
395 else {
396 0 $nn = $self->createTextNode($doc, $value);
397 0 $node->appendChild($nn);
398 }
399 }
400  
401 11 with 'PRANG::Graph::Node';
402  
403 11 1;
404  
405 __END__
406  
407 =head1 NAME
408  
409 PRANG::Graph::Element - accept a particular type of element
410  
411 =head1 SYNOPSIS
412  
413 See L<PRANG::Graph::Meta::Element> source and
414 L<PRANG::Graph::Node> for examples and information.
415  
416 =head1 DESCRIPTION
417  
418 This graph node specifies that the XML graph at this point must accept
419 a particular type of element.
420  
421 If the element only has only simple types (eg Str, Bool), it will not
422 have one of these objects in its graph.
423  
424 Along with L<PRANG::Graph::Text>, this graph node is the only type
425 which may actually consume input XML nodes or emit them on output.
426 The other node types merely change the state in the
427 L<PRANG::Graph::Context> object.
428  
429 =head1 ATTRIBUTES
430  
431 =over
432  
433 =item B<Str xmlns>
434  
435 If set, then the XML namespace of this element is expected to be the
436 value passed (or absent). This is generally not set if the namespace
437 of this portion of the graph is the same as the parent class.
438  
439 =item B<nodeName>
440  
441 This map is used for emitting and generating error messages. Also, if
442 set to C<*> it has special meaning when parsing. Specifies the name
443 of the node.
444  
445 =item B<nodeName_attr>
446  
447 If set, instances have an attribute which stores the name of the XML
448 element.
449  
450 =item B<Str nodeClass>
451  
452 This specifies the next type of element; during parsing and emitting,
453 recursion to the meta-object of this class occurs.
454  
455 This will be undefined if the attribute has C<Bool> type; node
456 presence is true and absence is false.
457  
458 =item B<attrName>
459  
460 Used when emitting; specifies the method to call to retrieve the item
461 to be output. Also used when parsing, to return the Moose attribute
462 slot for construction.
463  
464 =back
465  
466 =head1 SEE ALSO
467  
468 L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>,
469 L<PRANG::Graph::Context>, L<PRANG::Graph::Node>
470  
471 =head1 AUTHOR AND LICENCE
472  
473 Development commissioned by NZ Registry Services, and carried out by
474 Catalyst IT - L<http://www.catalyst.net.nz/>
475  
476 Copyright 2009, 2010, NZ Registry Services. This module is licensed
477 under the Artistic License v2.0, which permits relicensing under other
478 Free Software licenses.
479  
480 =cut
481  
« PRANG/Graph/Meta/Element.pm ↑ Summary PRANG/Marshaller.pm »