File Coverage

blib/lib/W3C/SOAP/XSD/Document/Element.pm
Criterion Covered Total %
statement 27 146 18.4
branch 0 52 0.0
condition 0 90 0.0
subroutine 9 21 42.8
pod 6 6 100.0
total 42 315 13.3


line stmt bran cond sub pod time code
1             package W3C::SOAP::XSD::Document::Element;
2              
3             # Created on: 2012-05-26 19:04:09
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   2222 use Moose;
  1         2  
  1         7  
10 1     1   3547 use warnings;
  1         2  
  1         26  
11 1     1   5 use version;
  1         3  
  1         7  
12 1     1   67 use Carp;
  1         2  
  1         70  
13 1     1   5 use Scalar::Util;
  1         1  
  1         31  
14 1     1   4 use List::Util;
  1         2  
  1         52  
15             #use List::MoreUtils;
16 1     1   5 use Data::Dumper qw/Dumper/;
  1         2  
  1         41  
17 1     1   5 use English qw/ -no_match_vars /;
  1         2  
  1         7  
18 1     1   367 use W3C::SOAP::Utils qw/split_ns xml_error/;
  1         2  
  1         7  
19              
20             extends 'W3C::SOAP::XSD::Document::Type';
21              
22             our $VERSION = version->new('0.11');
23              
24             has complex_type => (
25             is => 'rw',
26             isa => 'Str',
27             builder => '_complex_type',
28             lazy => 1,
29             );
30             has type => (
31             is => 'rw',
32             isa => 'Str',
33             builder => '_type',
34             lazy => 1,
35             predicate => 'has_type',
36             );
37             has package => (
38             is => 'rw',
39             isa => 'Str',
40             builder => '_package',
41             lazy => 1,
42             );
43             has max_occurs => (
44             is => 'rw',
45             #isa => 'Str',
46             builder => '_max_occurs',
47             lazy => 1,
48             );
49             has min_occurs => (
50             is => 'rw',
51             #isa => 'Str',
52             builder => '_min_occurs',
53             lazy => 1,
54             );
55             has nillable => (
56             is => 'rw',
57             isa => 'Bool',
58             builder => '_nillable',
59             lazy => 1,
60             );
61             has choice_group => (
62             is => 'rw',
63             isa => 'Int',
64             );
65              
66             sub _complex_type {
67 0     0     my ($self) = @_;
68 0           my $complex;
69 0           my @nodes = $self->document->xpc->findnodes('xsd:complexType', $self->node);
70              
71 0           for my $node (@nodes) {
72             }
73              
74 0           return $complex;
75             }
76              
77             sub _type {
78 0     0     my ($self) = @_;
79 0           my $type = $self->node->getAttribute('type');
80 0 0         return $type if $type;
81              
82 0           my $simple = $self->document->simple_type;
83 0           TYPE:
84 0           for my $type (keys %{$simple}) {
85 0           my $node = $simple->{$type}->node;
86 0           my $type_name = $node->parentNode->getAttribute('name');
87 0 0 0       if ( $type_name && $self->name && $type_name eq $self->name ) {
      0        
88 0           my @children = $self->document->xpc->findnodes('xsd:restriction', $node);
89 0 0         last if @children != 1;
90              
91 0           my $child = $children[0]->firstChild;
92 0           while ($child) {
93 0 0         last TYPE if $child->nodeName !~ /^[#]/xms;
94 0           $child = $child->nextSibling;
95             }
96              
97 0           return $children[0]->getAttribute('base');
98             }
99 0   0       $type_name ||= '';
100             }
101              
102 0           return $self->has_anonymous;
103             }
104              
105             sub _package {
106 0     0     my ($self) = @_;
107 0           my $type = $self->type;
108 0           my ($ns, $name) = split_ns($type);
109 0   0       $ns ||= $self->document->ns_name;
110 0 0         my $ns_uri = $name ? $self->document->get_ns_uri($ns, $self->node) : '';
111 0   0       $name ||= $ns;
112              
113 0 0         if ( $ns_uri eq 'http://www.w3.org/2001/XMLSchema' ) {
114 0           return "xs:$name";
115             }
116              
117 0   0       my $base = $self->document->get_module_name( $ns_uri || $self->document->target_namespace );
118              
119 0           return $base . '::' . $name;
120             }
121              
122             sub _max_occurs {
123 0     0     my ($self) = @_;
124 0   0       return $self->node->getAttribute('maxOccurs') || 1;
125             }
126              
127             sub _min_occurs {
128 0     0     my ($self) = @_;
129 0   0       return $self->node->getAttribute('minOccurs') || 0;
130             }
131              
132             sub _nillable {
133 0     0     my ($self) = @_;
134 0           my $nillable = $self->node->getAttribute('nillable');
135              
136 0 0         return !$nillable ? 1
    0          
    0          
137             : $nillable eq 'true' ? 1
138             : $nillable eq 'false' ? 0
139             : die "Unknown value for attribute nillable in ".$self->node->toString;
140             }
141              
142             sub module {
143 0     0 1   my ($self) = @_;
144              
145 0           return $self->document->module;
146             }
147              
148             sub type_module {
149 0     0 1   my ($self) = @_;
150 0           my ($ns, $type) = split_ns($self->type);
151 0   0       $ns ||= $self->document->ns_name;
152 0           my $ns_uri = $self->document->get_ns_uri($ns, $self->node);
153              
154 0   0       return $self->simple_type || $self->document->get_module_name( $ns_uri ) . '::' . $type;
155             }
156              
157             sub simple_type {
158 0     0 1   my ($self) = @_;
159 0           $self->document->simple_type();
160 0           my ($ns, $type) = split_ns($self->type);
161 0   0       $ns ||= $self->document->ns_name;
162 0 0 0       return "xs:$type"
163             if $self->document->ns_map->{$ns}
164             && $self->document->ns_map->{$ns} eq 'http://www.w3.org/2001/XMLSchema';
165              
166 0           my $ns_uri = $self->document->get_ns_uri($ns, $self->node);
167 0 0 0       warn "Simple type missing a type for '".$self->type."'\n".xml_error($self->node)."\n"
168             if !$ns && $ns_uri ne 'http://www.w3.org/2001/XMLSchema';
169              
170 0 0         return "xs:$type" if $ns_uri eq 'http://www.w3.org/2001/XMLSchema';
171              
172 0           my @xsds = ($self->document);
173 0           while ( my $xsd = shift @xsds ) {
174 0           my $simple = $xsd->simple_type;
175 0 0 0       if ( !$simple && @{ $xsd->simple_types } ) {
  0            
176 0           $simple = $xsd->simple_type($xsd->_simple_type);
177             #warn $xsd->target_namespace . " $type => $simple\n" if $type eq 'GetCreateUIDResponseDto';
178             }
179              
180 0 0 0       return $simple->{$type}->moose_type if $simple && $simple->{$type};
181              
182 0           push @xsds, @{$xsd->imports};
  0            
183             }
184 0           return;
185             }
186              
187             sub very_simple_type {
188 0     0 1   my ($self) = @_;
189 0           $self->document->simple_type();
190 0           my ($ns, $type) = split_ns($self->type);
191 0   0       $ns ||= $self->document->ns_name;
192 0 0 0       return "xs:$type" if $self->document->ns_map->{$ns} && $self->document->ns_map->{$ns} eq 'http://www.w3.org/2001/XMLSchema';
193              
194 0           my $ns_uri = $self->document->get_ns_uri($ns, $self->node);
195 0 0 0       warn "Simple type missing a type for '".$self->type."'\n".xml_error($self->node)."\n"
196             if !$ns && $ns_uri ne 'http://www.w3.org/2001/XMLSchema';
197              
198 0 0         return "xs:$type" if $ns_uri eq 'http://www.w3.org/2001/XMLSchema';
199              
200 0           my @xsds = ($self->document);
201 0           while ( my $xsd = shift @xsds ) {
202 0           my $simple = $xsd->simple_type;
203 0 0 0       if ( !$simple && @{ $xsd->simple_types } ) {
  0            
204 0           $simple = $xsd->simple_type($xsd->_simple_type);
205             }
206              
207 0 0 0       return $simple->{$type}->type if $simple && $simple->{$type};
208              
209 0           push @xsds, @{$xsd->imports};
  0            
210             }
211 0           return;
212             }
213              
214             sub moosex_type {
215 0     0 1   my ($self) = @_;
216 0           my ($ns, $type) = split_ns($self->type);
217 0   0       $ns ||= $self->document->ns_name;
218 0           my $ns_uri = $self->document->get_ns_uri($ns, $self->node);
219 0 0 0       warn "Simple type missing a type for '".$self->type."'\n".xml_error($self->node)."\n"
220             if !$ns && $ns_uri ne 'http://www.w3.org/2001/XMLSchema';
221              
222 0 0         return "'xs:$type'" if $ns_uri eq 'http://www.w3.org/2001/XMLSchema';
223              
224 0           my @xsds = ($self->document);
225 0           while ( my $xsd = shift @xsds ) {
226 0           my $simple = $xsd->simple_type;
227 0 0 0       if ( !$simple && @{ $xsd->simple_types } ) {
  0            
228 0           $simple = $xsd->simple_type($xsd->_simple_type);
229             #warn $xsd->target_namespace . " $type => $simple\n" if $type eq 'GetCreateUIDResponseDto';
230             }
231              
232 0 0 0       return $simple->{$type}->moosex_type if $simple && $simple->{$type};
233              
234 0           push @xsds, @{$xsd->imports};
  0            
235             }
236 0           return;
237             }
238              
239             sub has_anonymous {
240 0     0 1   my ($self) = @_;
241 0 0 0       return if $self->has_type && $self->type;
242              
243 0           my %map = reverse %{ $self->document->ns_map };
  0            
244              
245 0           my $simple = $self->document->simple_type;
246 0           for my $type (keys %{$simple}) {
  0            
247 0           my $type_name = $simple->{$type}->node->parentNode->getAttribute('name');
248 0 0 0       if ( $type_name && $self->name && $type_name eq $self->name ) {
      0        
249 0           return $map{$self->document->target_namespace} . ':' . $type;
250             }
251 0   0       $type_name ||= '';
252             }
253              
254 0           my $complex = $self->document->complex_type;
255 0           for my $type (keys %{$complex}) {
  0            
256 0           my $type_name = $complex->{$type}->node->parentNode->getAttribute('name');
257 0 0 0       if ( $type_name && $self->name && $type_name eq $self->name ) {
      0        
258 0           return $map{$self->document->target_namespace} . ':' . $type;
259             }
260 0   0       $type_name ||= '';
261             }
262              
263 0   0       $self->document->ns_map->{xs} ||= 'http://www.w3.org/2001/XMLSchema';
264 0           return 'xs:string';
265             }
266              
267             1;
268              
269             __END__
270              
271             =head1 NAME
272              
273             W3C::SOAP::XSD::Document::Element - XML Schema Element
274              
275             =head1 VERSION
276              
277             This documentation refers to W3C::SOAP::XSD::Document::Element version 0.11.
278              
279              
280             =head1 SYNOPSIS
281              
282             use W3C::SOAP::XSD::Document::Element;
283              
284             # Brief but working code example(s) here showing the most common usage(s)
285             # This section will be as far as many users bother reading, so make it as
286             # educational and exemplary as possible.
287              
288              
289             =head1 DESCRIPTION
290              
291              
292             =head1 SUBROUTINES/METHODS
293              
294             =over 4
295              
296             =item C<module ()>
297              
298             =item C<type_module ()>
299              
300             =item C<very_simple_type ()>
301              
302             =item C<simple_type ()>
303              
304             =item C<moosex_type ()>
305              
306             =item C<has_anonymous ()>
307              
308             =back
309              
310             =head1 DIAGNOSTICS
311              
312             =head1 CONFIGURATION AND ENVIRONMENT
313              
314             =head1 DEPENDENCIES
315              
316             =head1 INCOMPATIBILITIES
317              
318             =head1 BUGS AND LIMITATIONS
319              
320             There are no known bugs in this module.
321              
322             Please report problems to Ivan Wills (ivan.wills@gmail.com).
323              
324             Patches are welcome.
325              
326             =head1 AUTHOR
327              
328             Ivan Wills - (ivan.wills@gmail.com)
329              
330             =head1 LICENSE AND COPYRIGHT
331              
332             Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
333             All rights reserved.
334              
335             This module is free software; you can redistribute it and/or modify it under
336             the same terms as Perl itself. See L<perlartistic>. This program is
337             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
338             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
339             PARTICULAR PURPOSE.
340              
341             =cut