blib/lib/W3C/SOAP/XSD/Parser.pm

filter: Statementstmt 92.2% 226 / 245 Branchbran 75.6% 59 / 78 Conditioncond 62.5% 30 / 48 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 78.1% 25 / 32 Podpod 100% 10 / 10 totaltotal 80.7% 357 / 442 CC 71 SCAR 26.8
CC
71
Cov
85%
element_attributes
30.7
write_modules
22.8
dynamic_classes
16.6
CRAP 14.7
« blib/lib/W3C/SOAP/XSD/Document.pm ↑ Summary blib/lib/W3C/SOAP/WSDL.pm »
1 package W3C::SOAP::XSD::Parser;
2  
3 # Created on: 2012-05-28 08:11:37
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;
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 7 ▶use List::MoreUtils qw/all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use W3C::SOAP::XSD::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use File::ShareDir qw/dist_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use Moose::Util::TypeConstraints;
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 W3C::SOAP::XSD;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 7 Moose::Exporter->setup_import_methods(
25 as_is => ['load_xsd'],
26 );
27  
28 7 extends 'W3C::SOAP::Parser';
29  
30 7 our $VERSION = 0.13;
31  
32 7 subtype xsd_documents =>
33 as 'ArrayRef[W3C::SOAP::XSD::Document]';
34 coerce xsd_documents =>
35 from 'W3C::SOAP::XSD::Document',
36 2 ▶ via {[$_]};
Subroutine __ANON__: called CC=1 SCAR=0.0
37 7 has '+document' => (
38 isa => 'xsd_documents',
39 coerce => 1,
40 );
41 7 has ns_module_map => (
42 is => 'rw',
43 isa => 'HashRef[Str]',
44 required => 1,
45 );
46  
47 sub write_modules {
48 3 ▶ my ($self) = @_;
Subroutine write_modules: called CC=21 SCAR=31.2
Pod documented
49 3 ▶ confess "No lib directory setup" if !$self->has_lib;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_lib 0 3 3
50 3 ▶ confess "No template object set" if !$self->has_template;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_template 0 3 3
51  
52 3 my @xsds = $self->get_schemas;
53 3 my $template = $self->template;
54 3 my @schemas;
55 my $self_module;
56 3 my @parents;
57 3 my @xsd_modules;
58  
59 # process the schemas
60 3 for my $xsd (@xsds) {
61 6 my $module = $xsd->module;
62 6 push @xsd_modules, $module;
63 6 ▶ $self_module ||= $module;
Condition66%2/3
$self_module ||= $module
l!l&&r!l&&!r
330
MC/DC0%0/2
$self_module ||= $module
$self_module $module
Truth table66%2/3
A ||= B
A= $self_moduleB= $module
ABresult
1X1
011
000
64 6 my $file = $self->lib . '/' . $module;
65 6 $file =~ s{::}{/}gxms;
66 6 $file = path($file);
67 6 my $parent = $file->parent;
68 6 my @missing;
69 6 ▶ while ( !-d $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $parent) 4 6 10
70 4 push @missing, $parent;
71 4 $parent = $parent->parent;
72 }
73 6 mkdir $_ for reverse @missing;
74  
75 6 for my $type ( @{ $xsd->complex_types } ) {
76 20 ▶ my $type_name = $type->name || $type->parent_node->name;
Condition33%1/3
$type->name || $type->parent_node->name
l!l&&r!l&&!r
2000
MC/DC0%0/2
$type->name || $type->parent_node->name
$type->name $type->parent_node->name
Truth table33%1/3
A || B
A= $type->nameB= $type->parent_node->name
ABresult
1X1
011
000
77 20 ▶ warn "me = ".(ref $type).
Branch: 1 branch
BranchTrueFalseTotal
unless $type_name 0 20 20
78 "\nnode = ".($type->node->nodeName).
79 "\nparent = ".(ref $type->parent_node).
80 "\nparent node = ".($type->node->parentNode->nodeName).
81 "\ndocument = ".(ref $type->document)."\n"
82 if !$type_name;
83 20 ▶ confess "No name found for ",
Branch: 1 branch
BranchTrueFalseTotal
unless $type_name 0 20 20
84 $type->node->toString,
85 "\nin :\n",
86 $type->document->string,"\n"
87 if !$type_name;
88 20 my $type_module = $module . '::' . $type_name;
89 20 push @parents, $type_module;
90 20 my $type_file = $self->lib . '/' . $type_module;
91 20 $type_file =~ s{::}{/}gxms;
92 20 $type_file = path($type_file);
93 20 ▶ mkdir $type_file->parent if !-d $type_file->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $type_file->parent 6 14 20
94  
95 20 my %modules;
96 20 for my $el (@{ $type->sequence }) {
97 396 ▶ $modules{ $el->type_module }++
Branch: 1 branch
BranchTrueFalseTotal
if not $el->simple_type and $el->module ne $module 0 396 396
Condition66%2/3
not $el->simple_type and $el->module ne $module
!ll&&!rl&&r
340560
MC/DC0%0/2
not $el->simple_type and $el->module ne $module
not $el->simple_type $el->module ne $module
Truth table66%2/3
not(A) and B
A= not $el->simple_typeB= $el->module ne $module
ABresult
0X0
100
111
98 if ! $el->simple_type && $el->module ne $module
99 }
100 20 for my $element (@{ $type->sequence }) {
101 396 ▶ next if $element->simple_type;
Branch: 1 branch
BranchTrueFalseTotal
if $element->simple_type 340 56 396
102 56 my ($ns) = split_ns($element->type);
103 56 ▶ $ns ||= $element->document->target_namespace;
Condition33%1/3
$ns ||= $element->document->target_namespace
l!l&&r!l&&!r
5600
MC/DC0%0/2
$ns ||= $element->document->target_namespace
$ns $element->document->target_namespace
Truth table33%1/3
A ||= B
A= $nsB= $element->document->target_namespace
ABresult
1X1
011
000
104 56 my $ns_uri = $element->document->get_ns_uri($ns, $element->node);
105 56 ▶ $modules{ $type->document->get_module_name($ns_uri) }++
Branch: 1 branch
BranchTrueFalseTotal
if $ns_uri and $ns_uri ne $type->document->target_namespace 1 55 56
Condition66%2/3
$ns_uri and $ns_uri ne $type->document->target_namespace
!ll&&!rl&&r
0551
MC/DC50%1/2
$ns_uri and $ns_uri ne $type->document->target_namespace
$ns_uri $ns_uri ne $type->document->target_namespace
Truth table66%2/3
A and B
A= $ns_uriB= $ns_uri ne $type->document->target_namespace
ABresult
0X0
100
111
106 if $ns_uri && $ns_uri ne $type->document->target_namespace;
107 }
108  
109 # write the complex type module
110 $self->write_module(
111 20 'xsd/complex_type.pm.tt',
112 {
113 xsd => $xsd,
114 module => $type_module,
115 modules => [ keys %modules ],
116 node => $type
117 },
118 "$type_file.pm"
119 );
120 }
121  
122 # write the simple types library
123 $self->write_module(
124 6 'xsd/base.pm.tt',
125 {
126 xsd => $xsd,
127 },
128 "$file/Base.pm"
129 );
130  
131 # write the "XSD" elements module
132 6 $self->write_module(
133 'xsd/pm.tt',
134 {
135 xsd => $xsd,
136 parents => \@parents,
137 w3c_version => $VERSION,
138 config => { xsd => { parent_module => $xsd->module . '::Base'}},
139 },
140 "$file.pm"
141 );
142  
143 }
144  
145 #warn Dumper \@xsd_modules, $self_module;
146 3 ▶ return wantarray ? @xsd_modules : $self_module;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
147 }
148  
149 7 my %written;
150 sub write_module {
151 32 ▶ my ($self, $tt, $template_data, $file) = @_;
Subroutine write_module: called CC=3 SCAR=11.6
Pod documented
152 32 my $template = $self->template;
153  
154 32 ▶ if ($written{$file}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($written{$file}++) 0 32 32
155 #warn "Already written $file!\n";
156 0 return;
157 }
158  
159 32 $template->process($tt, $template_data, "$file");
160 32 ▶ confess "Error in creating $file (via $tt): ". $template->error."\n"
Branch: 1 branch
BranchTrueFalseTotal
if $template->error 0 32 32
161 if $template->error;
162  
163 32 return;
164 }
165  
166 sub written_modules {
167 2 ▶ return keys %written;
Subroutine written_modules: called CC=1 SCAR=0.0
Pod documented
168 }
169  
170 sub get_schemas {
171 6 ▶ my ($self) = @_;
Subroutine get_schemas: called CC=7 SCAR=19.5
Pod documented
172 6 my @xsds = @{ $self->document };
173 6 my %xsd;
174  
175 # import all schemas
176 6 ▶ while ( my $xsd = shift @xsds ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xsd = shift @xsds) 14 6 20
177 14 my $target_namespace = $xsd->target_namespace;
178 14 push @{ $xsd{$target_namespace} }, $xsd;
179  
180 14 for my $import ( @{ $xsd->imports } ) {
181 4 push @xsds, $import;
182 }
183 14 for my $include ( @{ $xsd->includes } ) {
184 4 push @xsds, $include;
185 }
186 }
187  
188 # flatten schemas specified more than once
189 6 for my $ns ( keys %xsd ) {
190 12 my $xsd = pop @{ $xsd{$ns} };
191 12 ▶ if ( @{ $xsd{$ns} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$xsd{$ns};}) 2 10 12
192 2 for my $xsd_repeat ( @{ $xsd{$ns} } ) {
193 2 push @{ $xsd->simple_types }, @{ $xsd_repeat->simple_types };
194 2 push @{ $xsd->complex_types }, @{ $xsd_repeat->complex_types };
195 2 push @{ $xsd->elements }, @{ $xsd_repeat->elements };
196 }
197 }
198  
199 12 push @xsds, $xsd;
200 }
201  
202 6 return @xsds;
203 }
204  
205 sub load_xsd {
206 0 ▶ my ($location) = @_;
Subroutine load_xsd: not called CC=1 SCAR=6.9
Pod documented
207 0 my $parser = __PACKAGE__->new(
208 location => $location,
209 ns_module_map => {},
210 );
211  
212 0 return $parser->dynamic_classes;
213 }
214  
215 sub dynamic_classes {
216 3 ▶ my ($self) = @_;
Subroutine dynamic_classes: called CC=16 SCAR=28.1
Pod documented
217 3 my @xsds = $self->get_schemas;
218 3 my @packages;
219  
220 # construct the in memory module names
221 3 for my $xsd (@xsds) {
222 6 $xsd->module_base('Dynamic::XSD');
223 6 $xsd->module;
224 }
225  
226 3 my %seen;
227 my @ordered_xsds;
228 XSD:
229 3 ▶ while ( my $xsd = shift @xsds ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xsd = shift @xsds) 7 3 10
230 7 my $module = $xsd->module;
231  
232 # Complex types
233 7 my @types = @{ $xsd->complex_types };
234 7 my %local_seen;
235 TYPE:
236 7 ▶ while ( my $type = shift @types ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = shift @types) 16 6 22
237 16 ▶ my $type_name = $type->name || $type->parent_node->name;
Condition33%1/3
$type->name || $type->parent_node->name
l!l&&r!l&&!r
1600
MC/DC0%0/2
$type->name || $type->parent_node->name
$type->name $type->parent_node->name
Truth table33%1/3
A || B
A= $type->nameB= $type->parent_node->name
ABresult
1X1
011
000
238 16 my $type_module = $module . '::' . $type_name;
239  
240 16 ▶ if ( $type->extension && !$seen{ $type->extension }++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->extension and not $seen{$type->extension}++) 1 15 16
Condition100%3/3
$type->extension and not $seen{$type->extension}++
!ll&&!rl&&r
1321
MC/DC100%2/2
$type->extension and not $seen{$type->extension}++
$type->extension not $seen{$type->extension}++
Truth table100%3/3
A and not(B)
A= $type->extensionB= not $seen{$type->extension}++
ABresult
0X0
100
111
241 1 push @xsds, $xsd;
242 1 next XSD;
243 }
244 15 $local_seen{ $type_module }++;
245 }
246  
247 6 %seen = ( %seen, %local_seen );
248 6 push @ordered_xsds, $xsd;
249 }
250  
251 3 my %complex_seen = ( 'W3C::SOAP::XSD' => 1 );
252 3 for my $xsd (@ordered_xsds) {
253 6 my $module = $xsd->module;
254  
255 # Create simple types
256 6 $self->simple_type_package($xsd);
257  
258 # Complex types
259 6 my @complex_types = @{ $xsd->complex_types };
260 6 my %types;
261 6 ▶ while ( my $type = shift @complex_types ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = shift @complex_types) 15 6 21
262 15 ▶ my $type_name = $type->name || $type->parent_node->name;
Condition33%1/3
$type->name || $type->parent_node->name
l!l&&r!l&&!r
1500
MC/DC0%0/2
$type->name || $type->parent_node->name
$type->name $type->parent_node->name
Truth table33%1/3
A || B
A= $type->nameB= $type->parent_node->name
ABresult
1X1
011
000
263 15 my $type_module = $module . '::' . $type_name;
264 15 ▶ next if $types{$type_module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $types{$type_module}++ 0 15 15
265  
266 15 my %modules = ( 'W3C::SOAP::XSD' => 1 );
267 15 for my $el (@{ $type->sequence }) {
268 49 ▶ $modules{ $el->type_module }++
Branch: 1 branch
BranchTrueFalseTotal
if not $el->simple_type and $el->module ne $module 0 49 49
Condition66%2/3
not $el->simple_type and $el->module ne $module
!ll&&!rl&&r
4450
MC/DC0%0/2
not $el->simple_type and $el->module ne $module
not $el->simple_type $el->module ne $module
Truth table66%2/3
not(A) and B
A= not $el->simple_typeB= $el->module ne $module
ABresult
0X0
100
111
269 if ! $el->simple_type && $el->module ne $module
270 }
271 15 ▶ if ( $type->extension ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->extension) 2 13 15
272 2 $modules{ $type->extension }++
273 }
274  
275 15 ▶ if ( !all {$complex_seen{$_}} keys %modules ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless (&all(sub { $complex_seen{$_}; } , keys %modules)) 0 15 15
276 0 push @complex_types, $type;
277 0 next;
278 }
279  
280 15 $complex_seen{$type_module}++;
281 15 $self->complex_type_package($xsd, $type, $type_module, [ keys %modules ]);
282 }
283  
284 # elements package
285 6 $self->elements_package($xsd, $module);
286  
287 6 push @packages, $module;
288 }
289  
290 3 return @packages;
291 }
292  
293 sub simple_type_package {
294 6 ▶ my ($self, $xsd) = @_;
Subroutine simple_type_package: called CC=5 SCAR=16.5
Pod documented
295  
296 6 for my $subtype (@{ $xsd->simple_types }) {
297 12 ▶ next if !$subtype->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $subtype->name 6 6 12
298  
299 # Setup base simple types
300 6 ▶ if ( @{ $subtype->enumeration } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$subtype->enumeration;}) { } 2 4 6
301 2 enum(
302 $subtype->moose_type
303 => $subtype->enumeration
304 );
305 }
306 else {
307 4 subtype $subtype->moose_type =>
308 as $subtype->moose_base_type;
309 }
310  
311 # Add coercion from XML::LibXML nodes
312 coerce $subtype->moose_type =>
313 from 'XML::LibXML::Node' =>
314 6 ▶ via { $_->textContent };
Subroutine __ANON__: not called CC=1 SCAR=1.2
315  
316 6 ▶ if ($subtype->list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtype->list) 0 6 6
317 coerce $subtype->moose_type =>
318 from 'ArrayRef' =>
319 0 ▶ via { join ' ', @$_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
320 }
321 }
322  
323 6 return;
324 }
325  
326 sub complex_type_package {
327 15 ▶ my ($self, $xsd, $type, $class_name, $super) = @_;
Subroutine complex_type_package: called CC=2 SCAR=6.9
Pod documented
328  
329 15 my $class = Moose::Meta::Class->create(
330 $class_name,
331 superclasses => $super,
332 );
333  
334 15 $class->add_attribute(
335 '+xsd_ns',
336 default => $xsd->target_namespace,
337 required => 1,
338 );
339  
340 15 for my $node (@{ $type->sequence }) {
341 49 $self->element_attributes($class, $class_name, $node, $xsd, 1);
342 }
343  
344 15 return $class;
345 }
346  
347 sub elements_package {
348 6 ▶ my ($self, $xsd, $class_name) = @_;
Subroutine elements_package: called CC=2 SCAR=6.9
Pod documented
349  
350 6 my $class = Moose::Meta::Class->create(
351 $class_name,
352 superclasses => [ 'W3C::SOAP::XSD' ],
353 );
354  
355 6 $class->add_attribute(
356 '+xsd_ns',
357 default => $xsd->target_namespace,
358 required => 1,
359 );
360  
361 6 for my $node (@{ $xsd->elements }) {
362 16 $self->element_attributes($class, $class_name, $node, $xsd);
363 }
364  
365 6 return $class;
366 }
367  
368 sub element_attributes {
369 65 ▶ my ($self, $class, $class_name, $element, $xsd, $complex) = @_;
Subroutine element_attributes: called CC=20 SCAR=34.2
Pod documented
370  
371 65 my $simple = $element->simple_type;
372 65 my $very_simple = $element->very_simple_type;
373 65 ▶ my $is_array = $element->max_occurs eq 'unbounded'
Condition75%9/12
$element->max_occurs eq 'unbounded' || $element->max_occurs && $element->max_occurs > 1 || $element->min_occurs && $element->min_occurs > 1
l!l&&r!l&&!r
3062
$element->max_occurs eq "unbounded" or $element->max_occurs and $element->max_occurs > 1
l!l&&r!l&&!r
1262
$element->max_occurs and $element->max_occurs > 1
!ll&&!rl&&r
0622
$element->min_occurs and $element->min_occurs > 1
!ll&&!rl&&r
41210
MC/DC40%2/5
$element->max_occurs eq 'unbounded' || $element->max_occurs && $element->max_occurs > 1 || $element->min_occurs && $element->min_occurs > 1
$element->max_occurs eq "unbounded" $element->max_occurs $element->max_occurs > 1 $element->min_occurs $element->min_occurs > 1
Truth table50%4/8
A or B and C || D and E
A= $element->max_occurs eq "unbounded"B= $element->max_occursC= $element->max_occurs > 1D= $element->min_occursE= $element->min_occurs > 1
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
374 || ( $element->max_occurs && $element->max_occurs > 1 )
375 || ( $element->min_occurs && $element->min_occurs > 1 );
376 65 ▶ my $type_name = $simple || $element->type_module;
Condition66%2/3
$simple || $element->type_module
l!l&&r!l&&!r
49160
MC/DC0%0/2
$simple || $element->type_module
$simple $element->type_module
Truth table66%2/3
A || B
A= $simpleB= $element->type_module
ABresult
1X1
011
000
377 65 my $serialize = '';
378  
379 65 ▶ if ( $very_simple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($very_simple) 49 16 65
380 49 ▶ if ( $very_simple eq 'xs:boolean' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($very_simple eq 'xs:boolean') { } 1 48 49
elsif ($very_simple eq 'xs:date') { } 2 46 48
elsif ($very_simple eq 'xs:time') { } 0 46 46
381 1 ▶ $serialize = sub { $_ ? 'true' : 'false' };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
382 }
383 elsif ( $very_simple eq 'xs:date' ) {
384 $serialize = sub {
385 0 ▶ return $_->ymd if $_->time_zone->isa('DateTime::TimeZone::Floating');
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $_->time_zone->isa("DateTime::TimeZone::Floating") 0 0 0
386 0 my $d = DateTime::Format::Strptime::strftime('%F%z', $_);
387 0 $d =~ s/([+-]\d\d)(\d\d)$/$1:$2/xms;
388 0 return $d
389 2 };
390 }
391 elsif ( $very_simple eq 'xs:time' ) {
392 0 ▶ $serialize = sub { $_->hms };
Subroutine __ANON__: not called CC=1 SCAR=6.9
393 }
394 }
395  
396 65 my @extra;
397 65 ▶ push @extra, ( xs_perl_module => $element->type_module ) if !$simple;
Branch: 1 branch
BranchTrueFalseTotal
unless $simple 16 49 65
398 65 ▶ push @extra, ( xs_choice_group => $element->choice_group ) if $element->choice_group;
Branch: 1 branch
BranchTrueFalseTotal
if $element->choice_group 6 59 65
399 65 ▶ push @extra, ( xs_serialize => $serialize ) if $serialize;
Branch: 1 branch
BranchTrueFalseTotal
if $serialize 3 62 65
400  
401 65 ▶ confess "No perl name!\n".$element->node->parentNode->toString if !$element->perl_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $element->perl_name 0 65 65
402 65 ▶ $class->add_attribute(
Branch: 3 branches
BranchTrueFalseTotal
$simple ? : 49 16 65
!$complex || $xsd->element_form_default eq 'qualified' ? : 62 3 65
$element->max_occurs eq 'unbounded' ? : 1 64 65
Condition100%3/3
not $complex or $xsd->element_form_default eq "qualified"
l!l&&r!l&&!r
16463
MC/DC100%2/2
not $complex or $xsd->element_form_default eq "qualified"
not $complex $xsd->element_form_default eq "qualified"
Truth table100%3/3
not(A) or B
A= not $complexB= $xsd->element_form_default eq "qualified"
ABresult
1X1
011
000
403 $element->perl_name,
404 is => 'rw',
405 isa => $class_name->xsd_subtype(
406 ($simple ? 'parent' : 'module') => $type_name,
407 list => $is_array,
408 nillable => $element->nillable,
409 ),
410 predicate => 'has_'. $element->perl_name,
411 # TODO handle nillable correctly should be a Maybe type
412 #required => !$element->nillable,
413 coerce => 1,
414 #[%- IF config->alias && element->name.replace('^\w+:', '') != element->perl_name %]
415 #alias => '[% element->name.replace('^\w+:', '') %]',
416 #[%- END %]
417 traits => [qw{ W3C::SOAP::XSD }],
418 xs_name => $element->name,
419 xs_ns => !$complex || $xsd->element_form_default eq 'qualified' ? $xsd->target_namespace : '',
420 xs_type => $element->type,
421 xs_min_occurs => $element->min_occurs,
422 xs_max_occurs => $element->max_occurs eq 'unbounded' ? 0 : $element->max_occurs,
423 @extra,
424 );
425  
426 65 ▶ if ( $ENV{W3C_SOAP_NAME_STYLE} eq 'both' && $element->name ne $element->perl_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"W3C_SOAP_NAME_STYLE"} eq "both" and $element->name ne $element->perl_name) 0 65 65
Condition33%1/3
$ENV{"W3C_SOAP_NAME_STYLE"} eq "both" and $element->name ne $element->perl_name
!ll&&!rl&&r
6500
MC/DC0%0/2
$ENV{"W3C_SOAP_NAME_STYLE"} eq "both" and $element->name ne $element->perl_name
$ENV{"W3C_SOAP_NAME_STYLE"} eq "both" $element->name ne $element->perl_name
Truth table33%1/3
A and B
A= $ENV{"W3C_SOAP_NAME_STYLE"} eq "both"B= $element->name ne $element->perl_name
ABresult
0X0
100
111
427 0 my $name = $element->perl_name;
428 $class->add_method(
429 0 ▶ $element->name => sub { shift->$name(@_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
430 0 );
431 }
432  
433 65 return;
434 }
435 7 1;
436  
437 __END__
438  
439 =head1 NAME
440  
441 W3C::SOAP::XSD::Parser - Parser for XSD documents that generates Perl modules
442 implementing the object defined.
443  
444 =head1 VERSION
445  
446 This documentation refers to W3C::SOAP::XSD::Parser version 0.13.
447  
448 =head1 SYNOPSIS
449  
450 use W3C::SOAP::XSD::Parser;
451  
452 # Brief but working code example(s) here showing the most common usage(s)
453 # This section will be as far as many users bother reading, so make it as
454 # educational and exemplary as possible.
455  
456 =head1 DESCRIPTION
457  
458 =head1 SUBROUTINES/METHODS
459  
460 =over 4
461  
462 =item C<load_xsd ($schema_location)>
463  
464 Loads the schema and dynamically generates the Perl/Moose packages that
465 represent the schema.
466  
467 =item C<write_modules ()>
468  
469 Uses the supplied documents to write out perl modules to disk that represent
470 the XSDs in the documents.
471  
472 =item C<write_module ($tt, $data, $file)>
473  
474 Write the template to disk
475  
476 =item C<written_modules ()>
477  
478 Returns a list of all XSD modules written by the parser.
479  
480 =item C<get_schemas ()>
481  
482 Gets a list of the schemas imported/included from the base XML Schema(s)
483  
484 =item C<complex_type_package ( $xsd, $type, $class_name, $super)>
485  
486 Creates the complex types
487  
488 =item C<<$wsdl->dynamic_classes ()>>
489  
490 Creates a dynamic XSD objects that represent the XML Schema files imported.
491  
492 =item C<element_attributes ( $class, $class_name, $element )>
493  
494 Sets up all the attributes for a single element
495  
496 =item C<elements_package ( $xsd, $class_name )>
497  
498 Creates the package that represents top level elements in the XSD
499  
500 =item C<simple_type_package ( $xsd )>
501  
502 Creates all the simple types for the C<$xsd>
503  
504 =back
505  
506 =head1 DIAGNOSTICS
507  
508 =head1 CONFIGURATION AND ENVIRONMENT
509  
510 =head1 DEPENDENCIES
511  
512 =head1 INCOMPATIBILITIES
513  
514 =head1 BUGS AND LIMITATIONS
515  
516 There are no known bugs in this module.
517  
518 Please report problems to Ivan Wills (ivan.wills@gmail.com).
519  
520 Patches are welcome.
521  
522 =head1 AUTHOR
523  
524 Ivan Wills - (ivan.wills@gmail.com)
525  
526 =head1 LICENSE AND COPYRIGHT
527  
528 Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
529 All rights reserved.
530  
531 This module is free software; you can redistribute it and/or modify it under
532 the same terms as Perl itself. See L<perlartistic>. This program is
533 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
534 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
535 PARTICULAR PURPOSE.
536  
537 =cut
« blib/lib/W3C/SOAP/XSD/Document.pm ↑ Summary blib/lib/W3C/SOAP/WSDL.pm »