blib/lib/W3C/SOAP/XSD.pm

filter: Statementstmt 81.9% 173 / 211 Branchbran 68.4% 78 / 114 Conditioncond 44.4% 24 / 54 MC/DCmcdc 26.4% 9 / 34 Subroutinesub 65.7% 25 / 38 Podpod 100% 6 / 6 totaltotal 68.9% 315 / 457 CC 84 SCAR 30.4
CC
84
Cov
73%
to_data
51.3
xsd_subtype
34.3
_from_xml
30.0
CRAP 20.8
« blib/lib/W3C/SOAP/XSD/Document/Element.pm ↑ Summary blib/lib/W3C/SOAP/XSD/Document.pm »
1 package W3C::SOAP::XSD;
2  
3 # Created on: 2012-05-26 23:50:44
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Carp qw/carp croak cluck confess longmess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 #use List::MoreUtils;
15 7 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use MooseX::Types::XMLSchema;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use W3C::SOAP::XSD::Types qw/:all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use W3C::SOAP::XSD::Traits;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use W3C::SOAP::Utils qw/split_ns/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 ▶use DateTime::Format::Strptime qw/strptime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 7 extends 'W3C::SOAP::Base';
26  
27 7 our $VERSION = 0.13;
28  
29 7 has xsd_ns => (
30 is => 'rw',
31 isa => 'Str',
32 );
33 7 has xsd_ns_name => (
34 is => 'rw',
35 isa => 'Str',
36 predicate => 'has_xsd_ns_name',
37 clearer => 'clear_xsd_ns_name',
38 builder => '_xsd_ns_name',
39 lazy => 1,
40 );
41  
42 {
43 7 my %required;
44 my $require = sub {
45 2 ▶ my ($module) = @_;
Subroutine __ANON__: called CC=3 SCAR=13.5
46 2 ▶ return if $required{$module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $required{$module}++ 0 2 2
47 2 ▶ return if eval{ $module->can('new') };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $module->can("new") } } 2 0 2
48  
49 0 my $file = "$module.pm";
50 0 $file =~ s{::}{/}gxms;
51 0 require $file;
52 7 };
53 around BUILDARGS => sub {
54 25 ▶ my ($orig, $class, @args) = @_;
Subroutine __ANON__: called CC=13 SCAR=26.1
55 25 ▶ my $args
Branch: 2 branches
BranchTrueFalseTotal
!@args ? : 0 25 25
@args == 1 ? : 16 9 25
56 = !@args ? {}
57 : @args == 1 ? $args[0]
58 : {@args};
59  
60 25 ▶ if ( blessed $args && $args->isa('XML::LibXML::Node') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($args) and $args->isa("XML::LibXML::Node")) 7 18 25
Condition66%2/3
builtin::blessed($args) and $args->isa("XML::LibXML::Node")
!ll&&!rl&&r
1807
MC/DC50%1/2
builtin::blessed($args) and $args->isa("XML::LibXML::Node")
builtin::blessed($args) $args->isa("XML::LibXML::Node")
Truth table66%2/3
A and B
A= builtin::blessed($args)B= $args->isa("XML::LibXML::Node")
ABresult
0X0
100
111
61 7 my $xml = $args;
62 7 my $child = $xml->firstChild;
63 7 my $map = $class->xml2perl_map;
64 7 my ($element) = $class =~ /::([^:]+)$/xms;
65 7 $args = {};
66  
67 7 ▶ while ($child) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 15 7 22
68 15 ▶ if ( $child->nodeName !~ /^[#]/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($child->nodeName =~ /^[#]/msx) 11 4 15
69 11 my ($node_ns, $node) = split_ns($child->nodeName);
70 confess "Could not get node from (".$child->nodeName." via '$node_ns', '$node')\n"
71 11 ▶ if !$map->{$node};
Branch: 1 branch
BranchTrueFalseTotal
unless $map->{$node} 0 11 11
72 11 my $attrib = $map->{$node};
73 11 $node = $attrib->name;
74 11 ▶ my $module = $attrib->has_xs_perl_module ? $attrib->xs_perl_module : undef;
Branch: 1 branch
BranchTrueFalseTotal
$attrib->has_xs_perl_module ? : 2 9 11
75 11 ▶ $require->($module) if $module;
Branch: 1 branch
BranchTrueFalseTotal
if $module 2 9 11
76 11 ▶ my $value = $module ? $module->new($child) : $child->textContent;
Branch: 1 branch
BranchTrueFalseTotal
$module ? : 2 9 11
77  
78 $args->{$node}
79 = !exists $args->{$node} ? $value
80 : ref $args->{$node} ne 'ARRAY' ? [ $args->{$node} , $value ]
81 11 ▶ : [ @{$args->{$node}}, $value ];
Branch: 2 branches
BranchTrueFalseTotal
!exists $args->{$node} ? : 11 0 11
ref $args->{$node} ne 'ARRAY' ? : 0 0 0
82 }
83 15 $child = $child->nextSibling;
84 }
85 }
86  
87 25 return $class->$orig($args);
88 7 };
89 }
90  
91 7 my %ns_map;
92 7 my $count = 0;
93 sub _xsd_ns_name {
94 18 ▶ my ($self) = @_;
Subroutine _xsd_ns_name: called CC=1 SCAR=0.0
95 18 return $self->get_xsd_ns_name($self->xsd_ns);
96 }
97  
98 sub get_xsd_ns_name {
99 36 ▶ my ($self, $ns) = @_;
Subroutine get_xsd_ns_name: called CC=2 SCAR=6.9
Pod documented
100  
101 36 ▶ return $ns_map{$ns} if $ns_map{$ns};
Branch: 1 branch
BranchTrueFalseTotal
if $ns_map{$ns} 27 9 36
102  
103 9 return $ns_map{$ns} = 'WSX' . $count++;
104 }
105  
106 sub _from_xml {
107 0 ▶ my ($class, $type) = @_;
Subroutine _from_xml: not called CC=5 SCAR=34.0
108 0 my $xml = $_;
109 0 ▶ confess "Unknown conversion " . ( (ref $xml) || $xml )
Branch: 1 branch
BranchTrueFalseTotal
unless $xml and builtin::blessed($xml) and $xml->isa("XML::LibXML::Node") 0 0 0
Condition0%0/9
$xml and builtin::blessed($xml) and $xml->isa("XML::LibXML::Node")
!ll&&!rl&&r
000
$xml and builtin::blessed($xml)
!ll&&!rl&&r
000
ref $xml || $xml
l!l&&r!l&&!r
000
MC/DC0%0/3
$xml and builtin::blessed($xml) and $xml->isa("XML::LibXML::Node")
$xml builtin::blessed($xml) $xml->isa("XML::LibXML::Node")
MC/DC0%0/2
ref $xml || $xml
ref $xml $xml
Truth table0%0/4
A and B and C
A= $xmlB= builtin::blessed($xml)C= $xml->isa("XML::LibXML::Node")
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A || B
A= ref $xmlB= $xml
ABresult
1X1
011
000
110 if !$xml || !blessed $xml || !$xml->isa('XML::LibXML::Node');
111  
112 0 my $ret;
113  
114 try {
115 0 ▶ $ret = $type->new($xml);
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 }
117 catch {
118 0 ▶ $_ =~ s/\s at \s .*//xms;
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 0 warn "$class Failed in building from $type\->new($xml) : $_\n",
120 "Will use :\n\t'",
121 $xml->toString,
122 "'\n\tor\n\t'",
123 $xml->textContent,"'\n",
124 '*' x 222,
125 "\n";
126 0 $ret = $xml->textContent;
127 0 };
128  
129 0 return $ret;
130 }
131  
132 sub xml2perl_map {
133 17 ▶ my ($class) = @_;
Subroutine xml2perl_map: called CC=5 SCAR=16.1
Pod documented
134 17 my %map;
135  
136 17 for my $attr ($class->get_xml_nodes) {
137 37 $map{$attr->xs_name} = $attr;
138 }
139  
140 # get super class nodes (if any)
141 17 my $meta = $class->meta;
142  
143 17 for my $super ( $meta->superclasses ) {
144 18 ▶ next if !$super->can('xml2perl_map') && $super ne __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if not $super->can("xml2perl_map") and $super ne __PACKAGE__ 8 10 18
Condition66%2/3
not $super->can("xml2perl_map") and $super ne __PACKAGE__
!ll&&!rl&&r
1008
MC/DC50%1/2
not $super->can("xml2perl_map") and $super ne __PACKAGE__
not $super->can("xml2perl_map") $super ne __PACKAGE__
Truth table66%2/3
not(A) and B
A= not $super->can("xml2perl_map")B= $super ne __PACKAGE__
ABresult
0X0
100
111
145 10 %map = ( %{ $super->xml2perl_map }, %map );
146 }
147  
148 17 return \%map;
149 }
150  
151 sub to_xml {
152 18 ▶ my ($self, $xml) = @_;
Subroutine to_xml: called CC=20 SCAR=31.5
Pod documented
153 18 ▶ confess "No XML document passed to attach nodes to!" if !$xml;
Branch: 1 branch
BranchTrueFalseTotal
unless $xml 0 18 18
154 18 my $child;
155 18 my $meta = $self->meta;
156 18 my @attributes = $self->get_xml_nodes;
157  
158 18 my @nodes;
159 18 $self->clear_xsd_ns_name;
160 18 ▶ my $xsd_ns_name = $self->xsd_ns ? $self->xsd_ns_name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->xsd_ns ? : 18 0 18
161  
162 18 for my $att (@attributes) {
163 64 my $name = $att->name;
164  
165 # skip attributes that are not XSD attributes
166 64 ▶ next if !$att->does('W3C::SOAP::XSD');
Branch: 1 branch
BranchTrueFalseTotal
unless $att->does("W3C::SOAP::XSD") 0 64 64
167 64 my $has = "has_$name";
168  
169 # skip sttributes that are not set
170 64 ▶ next if !$self->$has;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$has 34 30 64
171  
172 30 ▶ my $xml_name = $att->has_xs_name ? $att->xs_name : $name;
Branch: 1 branch
BranchTrueFalseTotal
$att->has_xs_name ? : 30 0 30
173 30 ▶ my $xml_ns = $att->has_xs_ns ? $att->xs_ns : $self->xsd_ns;
Branch: 1 branch
BranchTrueFalseTotal
$att->has_xs_ns ? : 30 0 30
174 30 ▶ my $xml_ns_name
Branch: 2 branches
BranchTrueFalseTotal
!defined($xml_ns) ? : 0 30 30
$xml_ns ? : 18 12 30
175 = !defined $xml_ns ? $xsd_ns_name
176 : $xml_ns ? $self->get_xsd_ns_name($xml_ns)
177 : '';
178  
179 30 ▶ my $value = ref $self->$name eq 'ARRAY' ? $self->$name : [$self->$name];
Branch: 1 branch
BranchTrueFalseTotal
ref $self->$name eq 'ARRAY' ? : 2 28 30
180  
181 30 for my $item (@$value) {
182 30 ▶ my $tag = $xml->createElement($xml_ns_name ? $xml_ns_name . ':' . $xml_name : $xml_name);
Branch: 1 branch
BranchTrueFalseTotal
$xml_ns_name ? : 18 12 30
183 30 ▶ $tag->setAttribute("xmlns:$xml_ns_name" => $xml_ns) if $xml_ns;
Branch: 1 branch
BranchTrueFalseTotal
if $xml_ns 18 12 30
184  
185 30 ▶ if ( blessed($item) && $item->can('to_xml') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($item) and $item->can('to_xml')) { } 9 21 30
elsif (not defined $item || $att->has_xs_serialize) { } 0 21 21
Condition66%2/3
builtin::blessed($item) and $item->can("to_xml")
!ll&&!rl&&r
2109
MC/DC50%1/2
builtin::blessed($item) and $item->can("to_xml")
builtin::blessed($item) $item->can("to_xml")
Truth table66%2/3
A and B
A= builtin::blessed($item)B= $item->can("to_xml")
ABresult
0X0
100
111
186 #$item->xsd_ns_name( $xsd_ns_name ) if !$item->has_xsd_ns_name;
187 9 my @children = $item->to_xml($xml);
188 9 $tag->appendChild($_) for @children;
189 }
190 ▶ elsif ( ! defined $item && ! $att->has_xs_serialize ) {
Condition33%1/3
defined $item || $att->has_xs_serialize
l!l&&r!l&&!r
2100
MC/DC0%0/2
defined $item || $att->has_xs_serialize
defined $item $att->has_xs_serialize
Truth table33%1/3
A || B
A= defined $itemB= $att->has_xs_serialize
ABresult
1X1
011
000
191 0 $tag->setAttribute('nil', 'true');
192 0 $tag->setAttribute('null', 'true');
193 }
194 else {
195 21 local $_ = $item;
196 21 ▶ my $text
Branch: 1 branch
BranchTrueFalseTotal
$att->has_xs_serialize ? : 0 21 21
197 = $att->has_xs_serialize
198 ? $att->xs_serialize->($item)
199 : "$item";
200 21 $tag->appendChild( $xml->createTextNode($text) );
201 }
202  
203 30 push @nodes, $tag;
204 }
205 }
206  
207 18 return @nodes;
208 }
209  
210 sub to_data {
211 10 ▶ my ($self, %option) = @_;
Subroutine to_data: called CC=17 SCAR=39.4
Pod documented
212 10 my $child;
213 10 my $meta = $self->meta;
214 10 my @attributes = $self->get_xml_nodes;
215  
216 10 my %nodes;
217  
218 10 for my $att (@attributes) {
219 22 my $name = $att->name;
220  
221 # skip attributes that are not XSD attributes
222 22 ▶ next if !$att->does('W3C::SOAP::XSD');
Branch: 1 branch
BranchTrueFalseTotal
unless $att->does("W3C::SOAP::XSD") 0 22 22
223 22 my $has = "has_$name";
224  
225 # skip sttributes that are not set
226 22 ▶ next if !$self->$has;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$has 0 22 22
227  
228 22 ▶ my $key_name = $att->has_xs_name && $option{like_xml} ? $att->xs_name : $name;
Branch: 1 branch
BranchTrueFalseTotal
$att->has_xs_name && $option{'like_xml'} ? : 0 22 22
Condition33%1/3
$att->has_xs_name and $option{"like_xml"}
!ll&&!rl&&r
0220
MC/DC0%0/2
$att->has_xs_name and $option{"like_xml"}
$att->has_xs_name $option{"like_xml"}
Truth table33%1/3
A and B
A= $att->has_xs_nameB= $option{"like_xml"}
ABresult
0X0
100
111
229 22 my $value = $self->$name;
230  
231 22 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 22 22
232 0 my @elements;
233 0 for my $element (@$value) {
234 0 ▶ if ( blessed($element) && $element->can('to_data') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($element) and $element->can("to_data")) 0 0 0
Condition0%0/3
builtin::blessed($element) and $element->can("to_data")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($element) and $element->can("to_data")
builtin::blessed($element) $element->can("to_data")
Truth table0%0/3
A and B
A= builtin::blessed($element)B= $element->can("to_data")
ABresult
0X0
100
111
235 0 push @elements, $element->to_data(%option);
236 }
237 }
238 0 $nodes{$key_name} = \@elements;
239 }
240 else {
241 22 ▶ if ( blessed($value) && $value->can('to_data') ) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($value) and $value->can('to_data')) { } 5 17 22
elsif (not defined $value || $att->has_xs_serialize) { } 0 17 17
elsif ($option{'stringify'}) { } 0 17 17
Condition66%2/3
builtin::blessed($value) and $value->can("to_data")
!ll&&!rl&&r
1705
MC/DC50%1/2
builtin::blessed($value) and $value->can("to_data")
builtin::blessed($value) $value->can("to_data")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->can("to_data")
ABresult
0X0
100
111
242 5 $value = $value->to_data(%option);
243 }
244 ▶ elsif ( ! defined $value && ! $att->has_xs_serialize ) {
Condition33%1/3
defined $value || $att->has_xs_serialize
l!l&&r!l&&!r
1700
MC/DC0%0/2
defined $value || $att->has_xs_serialize
defined $value $att->has_xs_serialize
Truth table33%1/3
A || B
A= defined $valueB= $att->has_xs_serialize
ABresult
1X1
011
000
245 }
246 elsif ($option{stringify}) {
247 0 local $_ = $value;
248 0 ▶ my $text
Branch: 1 branch
BranchTrueFalseTotal
$att->has_xs_serialize ? : 0 0 0
249 = $att->has_xs_serialize
250 ? $att->xs_serialize->($value)
251 : "$value";
252 0 ▶ $value = defined $value ? $text : $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
253 }
254  
255 22 $nodes{$key_name} = $value;
256 }
257 }
258  
259 10 return \%nodes;
260 }
261  
262 sub get_xml_nodes {
263 60 ▶ my ($self) = @_;
Subroutine get_xml_nodes: called CC=4 SCAR=13.9
Pod documented
264 60 my $meta = $self->meta;
265  
266 60 my @parent_nodes;
267 60 my @supers = $meta->superclasses;
268 60 for my $super (@supers) {
269 65 ▶ push @parent_nodes, $super->get_xml_nodes if $super ne __PACKAGE__ && eval { $super->can('get_xml_nodes') };
Branch: 1 branch
BranchTrueFalseTotal
if $super ne __PACKAGE__ and eval { do { $super->can("get_xml_nodes") } } 15 50 65
Condition100%3/3
$super ne __PACKAGE__ and eval {
!ll&&!rl&&r
42815
MC/DC100%2/2
$super ne __PACKAGE__ and eval { do { $super->can("get_xml_nodes") } }
$super ne __PACKAGE__ eval { do { $super->can("get_xml_nodes") } }
Truth table100%3/3
A and B
A= $super ne __PACKAGE__B= eval { do { $super->can("get_xml_nodes") } }
ABresult
0X0
100
111
270 }
271  
272 return @parent_nodes, map {
273 123 $meta->get_attribute($_)
274 }
275 sort {
276 162 $meta->get_attribute($a)->insertion_order <=> $meta->get_attribute($b)->insertion_order
277 }
278 grep {
279 60 $meta->get_attribute($_)->does('W3C::SOAP::XSD::Traits')
280 }
281 $meta->get_attribute_list;
282 }
283  
284 7 my %types;
285 sub xsd_subtype {
286 481 ▶ my ($self, %args) = @_;
Subroutine xsd_subtype: called CC=20 SCAR=35.4
Pod documented
287 481 ▶ my $parent_type = $args{module} || $args{parent};
Condition66%2/3
$args{'module'} || $args{'parent'}
l!l&&r!l&&!r
873940
MC/DC0%0/2
$args{'module'} || $args{'parent'}
$args{'module'} $args{'parent'}
Truth table66%2/3
A || B
A= $args{'module'}B= $args{'parent'}
ABresult
1X1
011
000
288  
289 # upgrade types
290 481 ▶ $parent_type
Branch: 6 branches
BranchTrueFalseTotal
$parent_type eq 'xs:date' ? : 4 477 481
$parent_type eq 'xs:dateTime' ? : 35 442 477
$parent_type eq 'xs:boolean' ? : 2 440 442
$parent_type eq 'xs:double' ? : 3 437 440
$parent_type eq 'xs:decimal' ? : 3 434 437
$parent_type eq 'xs:long' ? : 0 434 434
291 = $parent_type eq 'xs:date' ? 'xsd:date'
292 : $parent_type eq 'xs:dateTime' ? 'xsd:dateTime'
293 : $parent_type eq 'xs:boolean' ? 'xsd:boolean'
294 : $parent_type eq 'xs:double' ? 'xsd:double'
295 : $parent_type eq 'xs:decimal' ? 'xsd:decimal'
296 : $parent_type eq 'xs:long' ? 'xsd:long'
297 : $parent_type;
298  
299 my $parent_type_name
300 = $args{list} ? "ArrayRef[$parent_type]"
301 481 ▶ : $args{nillable} ? "Maybe[$parent_type]"
Branch: 2 branches
BranchTrueFalseTotal
$args{'list'} ? : 7 474 481
$args{'nillable'} ? : 466 8 474
302 : $parent_type;
303  
304 481 ▶ my $subtype = $parent_type =~ /^xsd:\w/xms && Moose::Util::TypeConstraints::find_type_constraint($parent_type);
Condition66%2/3
$parent_type =~ /^xsd:\w/msx && Moose::Util::TypeConstraints::find_type_constraint($parent_type)
!ll&&!rl&&r
434047
MC/DC50%1/2
$parent_type =~ /^xsd:\w/msx && Moose::Util::TypeConstraints::find_type_constraint($parent_type)
$parent_type =~ /^xsd:\w/msx Moose::Util::TypeConstraints::find_type_constraint($parent_type)
Truth table66%2/3
A && B
A= $parent_type =~ /^xsd:\w/msxB= Moose::Util::TypeConstraints::find_type_constraint($parent_type)
ABresult
0X0
100
111
305 481 ▶ return $subtype if $subtype && !($args{list} || $args{simple_list});
Branch: 1 branch
BranchTrueFalseTotal
if $subtype and not $args{"list"} || $args{"simple_list"} 3 478 481
Condition83%5/6
$subtype and not $args{"list"} || $args{"simple_list"}
!ll&&!rl&&r
434443
$args{'list'} || $args{'simple_list'}
l!l&&r!l&&!r
0443
MC/DC66%2/3
$subtype and not $args{"list"} || $args{"simple_list"}
$subtype $args{'list'} $args{'simple_list'}
Truth table75%3/4
A and not(B || C)
A= $subtypeB= $args{'list'}C= $args{'simple_list'}
ABCresult
0XX0
11X0
1010
1001
306  
307 $subtype = subtype
308 as $parent_type_name,
309 478 ▶ message {"'$_' failed to validate as a $parent_type"};
Subroutine __ANON__: not called CC=1 SCAR=1.2
310  
311 478 ▶ if ( $args{list} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'list'}) { } 7 471 478
elsif ($args{'module'}) { } 80 391 471
312 7 ▶ if ( $args{module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'module'}) { } 7 0 7
313 coerce $subtype =>
314 from 'xml_node' =>
315 7 ▶ via { [$parent_type->new($_)] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
316 coerce $subtype =>
317 from 'HashRef' =>
318 7 ▶ via { [$parent_type->new($_)] };
Subroutine __ANON__: called CC=1 SCAR=0.0
319 coerce $subtype =>
320 from 'ArrayRef[HashRef]' =>
321 7 ▶ via { [ map { $parent_type->new($_) } @$_ ] };
Subroutine __ANON__: not called CC=1 SCAR=2.6
322 coerce $subtype =>
323 from $parent_type =>
324 7 ▶ via { [$_] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
325 }
326 else {
327 coerce $subtype =>
328 from 'xml_node' =>
329 0 ▶ via { [$_->textContent] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
330 coerce $subtype =>
331 from 'ArrayRef[xml_node]' =>
332 0 ▶ via { [ map { $_->textContent } @$_ ] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
333 }
334 }
335 elsif ( $args{module} ) {
336 coerce $subtype =>
337 from 'xml_node' =>
338 80 ▶ via { $parent_type->new($_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
339 coerce $subtype =>
340 from 'HashRef' =>
341 80 ▶ via { $parent_type->new($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
342 }
343 else {
344 coerce $subtype =>
345 from 'xml_node' =>
346 391 ▶ via { $_->textContent };
Subroutine __ANON__: not called CC=1 SCAR=1.2
347 }
348  
349 478 ▶ if ($args{simple_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"simple_list"}) 416 62 478
350 coerce $subtype =>
351 from "ArrayRef" =>
352 416 ▶ via { join ' ', @$_ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
353 }
354 # Propogate coercion from Any via parent's type coercion.
355 478 my $this_type = $subtype->parent;
356 478 ▶ if ($this_type->has_parent && ref $this_type->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_type->has_parent and ref $this_type->parent) 478 0 478
Condition33%1/3
$this_type->has_parent and ref $this_type->parent
!ll&&!rl&&r
00478
MC/DC0%0/2
$this_type->has_parent and ref $this_type->parent
$this_type->has_parent ref $this_type->parent
Truth table33%1/3
A and B
A= $this_type->has_parentB= ref $this_type->parent
ABresult
0X0
100
111
357 coerce $subtype
358 => from 'Any'
359 => via {
360 !defined $_ && $args{nillable} ? undef
361 0 ▶ : $args{nillable} ? Moose::Util::TypeConstraints::find_type_constraint($parent_type)->coerce($_)
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
!defined($_) && $args{'nillable'} ? : 0 0 0
$args{'nillable'} ? : 0 0 0
Condition0%0/3
not defined $_ and $args{"nillable"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $_ and $args{"nillable"}
not defined $_ $args{"nillable"}
Truth table0%0/3
not(A) and B
A= not defined $_B= $args{"nillable"}
ABresult
0X0
100
111
362 : $this_type->parent->coerce($_)
363 478 };
364 }
365  
366 478 return $subtype;
367 }
368  
369 7 1;
370  
371 __END__
372  
373 =head1 NAME
374  
375 W3C::SOAP::XSD - The parent module for generated XSD modules.
376  
377 =head1 VERSION
378  
379 This documentation refers to W3C::SOAP::XSD version 0.13.
380  
381 =head1 SYNOPSIS
382  
383 use W3C::SOAP::XSD;
384  
385 # Brief but working code example(s) here showing the most common usage(s)
386 # This section will be as far as many users bother reading, so make it as
387 # educational and exemplary as possible.
388  
389  
390 =head1 DESCRIPTION
391  
392  
393 =head1 SUBROUTINES/METHODS
394  
395 =over 4
396  
397 =item C<get_xsd_ns_name ($ns)>
398  
399 Returns the namespace name for a particular namespace.
400  
401 =item C<xml2perl_map ()>
402  
403 Returns a mapping of XML tag elements to perl attributes
404  
405 =item C<to_xml ($xml)>
406  
407 Converts the object to an L<XML::LibXML> node.
408  
409 =item C<to_data (%options)>
410  
411 Converts this object to a perl data structure. If C<$option{like_xml}> is
412 specified and true, the keys will be the same as the XML tags otherwise the
413 keys will be perl names. If C<$option{stringify}> is true and specified
414 any non XSD objects will be stringified (eg DateTime objects).
415  
416 =item C<get_xml_nodes ()>
417  
418 Returns a list of attributes of the current object that have the
419 C<W3C::SOAP::XSD> trait (which is defined in L<W3C::SOAP::XSD::Traits>)
420  
421 =item C<xsd_subtype ()>
422  
423 Helper method to create XSD subtypes that do coercions form L<XML::LibXML>
424 objects and strings.
425  
426 =back
427  
428 =head1 DIAGNOSTICS
429  
430 =head1 CONFIGURATION AND ENVIRONMENT
431  
432 =head1 DEPENDENCIES
433  
434 =head1 INCOMPATIBILITIES
435  
436 =head1 BUGS AND LIMITATIONS
437  
438 There are no known bugs in this module.
439  
440 Please report problems to Ivan Wills (ivan.wills@gmail.com).
441  
442 Patches are welcome.
443  
444 =head1 AUTHOR
445  
446 Ivan Wills - (ivan.wills@gmail.com)
447  
448 =head1 LICENSE AND COPYRIGHT
449  
450 Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
451 All rights reserved.
452  
453 This module is free software; you can redistribute it and/or modify it under
454 the same terms as Perl itself. See L<perlartistic>. This program is
455 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
456 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
457 PARTICULAR PURPOSE.
458  
459 =cut
« blib/lib/W3C/SOAP/XSD/Document/Element.pm ↑ Summary blib/lib/W3C/SOAP/XSD/Document.pm »