File Coverage

lib/SOAP/WSDL/XSD/Typelib/Element.pm
Criterion Covered Total %
statement 31 31 100.0
branch 16 16 100.0
condition 4 6 66.6
subroutine 8 8 100.0
pod 0 2 0.0
total 59 63 93.6


line stmt bran cond sub pod time code
1             package SOAP::WSDL::XSD::Typelib::Element;
2 14     14   4732 use strict; use warnings;
  14     14   28  
  14         484  
  14         68  
  14         29  
  14         439  
3 14     14   4330 use Class::Std::Fast::Storable constructor => 'none';
  14         126091  
  14         145  
4              
5             our $VERSION = $SOAP::WSDL::VERSION;
6              
7             my %NAME;
8             my %NILLABLE;
9             my %REF;
10             my %MIN_OCCURS;
11             my %MAX_OCCURS;
12              
13             # TODO replace by generated methods?
14             #
15             # Class data - remember, we're the base class for a class factory or for
16             # generated code...
17             # use BLOCK: for scoping
18             BLOCK: {
19             my %method_lookup = (
20             _name => \%NAME,
21             _nillable => \%NILLABLE,
22             _ref => \%REF,
23             _minOccurs => \%MIN_OCCURS,
24             _maxOccurs => \%MAX_OCCURS,
25             );
26              
27             # create getters / setters for all elements' class data
28 14     14   3352 no strict qw(refs);
  14         31  
  14         6931  
29             while (my ($name, $value) = each %method_lookup ) {
30             *{ "__set$name" } = sub {
31 105 100   105   1599 @_ or die "Cannot call __set$name without parameter";
32 104   66     314 my $class = ref $_[0] || $_[0];
33 104         355 $value->{ $class } = $_[1];
34             };
35             *{ "__get$name" } = sub {
36 6 100   6   67 @_ or die "Cannot call __set$name as function";
37 5   66     14 my $class = ref $_[0] || $_[0];
38 5         24 return $value->{ $class };
39             };
40             }
41             };
42              
43              
44             # use $_[0] and $_[1] for speed.
45              
46             sub start_tag {
47             # my ($self, $opt, $value) = @_;
48 23 100   23 0 82 my $ending = ($_[1]->{ empty }) ? '/>' : '>';
49 23         39 my @attr_from = ();
50              
51 23 100       73 if ($_[1]->{ nil }) {
52 3 100       13 return q{} if not $NILLABLE{ ref $_[0] };
53 2         4 push @attr_from, q{ xsi:nil="true"};
54 2         4 $ending = '/>';
55             }
56 22 100       67 if (delete $_[1]->{qualified}) {
57 10         52 push @attr_from, q{ xmlns="} . $_[0]->get_xmlns() . q{"};
58             }
59 22         170 push @attr_from, $_[0]->serialize_attr();
60              
61             # do we need to check for name ? Element ref="" should have it's own
62             # start_tag. If we don't need to check, we can speed things up
63 22 100       179 return join q{}, "<$_[1]->{ name }" , @attr_from , $ending if $_[1]->{ name };
64 12         88 return join q{}, "<$NAME{ ref $_[0]}" , @attr_from , $ending;
65             }
66              
67             # use $_[0] and $_[1] for speed.
68             #
69             # read it as:
70             #
71             # my ($self, $opt) = @_;
72             # my $class = ref $self;
73             # return "{name}>" if $opt->{name};
74             # return "";
75             #
76             # do we need to check for name ? Element ref="" should have it's own
77             # end_tag. If we don't need to check, we can speed things up by defining
78             # end tag with () prototype - perl will inline it for us if we do...
79             sub end_tag {
80 18 100   18 0 122 return "{name}>" if $_[1]->{name};
81 8         76 return "";
82             }
83              
84             1;
85              
86             =pod
87              
88             =head1 NAME
89              
90             SOAP::WSDL::XSD::Typelib::Element - element base clase
91              
92             =head1 SYNOPSIS
93              
94             This example creates a class for this XML schema definition:
95              
96            
97             minOccurs="1" maxOccurs="1"/>
98              
99             package MyElement;
100             use strict;
101             use Class::Std::Fast::Storable constructor => 'none';
102             use base (
103             'SOAP::WSDL::XSD::Typelib::Element',
104             'SOAP::WSDL::XSD::Typelib::Builtin::string',
105             );
106              
107             __PACKAGE__->__set_name('MyElementName');
108             __PACKAGE__->__set_nillable(1);
109             __PACKAGE__->__set_minOccurs(1);
110             __PACKAGE__->__set_maxOccurs(1);
111             __PACKAGE__->__set_ref(0);
112              
113             Now we create this XML schema definition type class:
114              
115            
116              
117             package MyElement2;
118             use strict;
119             use Class::Std::Fast::Storable constructor => 'none';
120             use base (
121             'SOAP::WSDL::XSD::Typelib::Element',
122             'MyElement'
123             );
124              
125             __PACKAGE__->__set_name('MyElementName');
126             __PACKAGE__->__set_nillable(0);
127             __PACKAGE__->__set_ref(1);
128              
129             =head1 NOTES
130              
131             =over
132              
133             =item * type="Foo"
134              
135             Implemented via inheritance.
136              
137             =item * ref="Foo"
138              
139             Implemented via inheritance, too. Calling
140              
141             __PACKAGE__->__set_ref(1) is highly encouraged, though it has no
142             effect yet - it will probably be needed for serialization to XML
143             Schema definitions some day.
144              
145             =back
146              
147             =head1 BUGS AND LIMITATIONS
148              
149             =over
150              
151             =item * minOccurs maxOccurs not implemented
152              
153             These attributes are not yet supported, though they may be set as class
154             properties via __PACKAGE__->__set_FOO methods.
155              
156             =item * 'http://www.w3.org/2001/XMLSchema-instance prefix is hardcoded
157              
158             The prefix for 'http://www.w3.org/2001/XMLSchema-instance (used as namespace
159             for the {http://www.w3.org/2001/XMLSchema-instance}nil="true" attribute
160             is hardcoded as 'xsi'.
161              
162             You should definitly provide your XML envelope generator with the same prefix
163             namespace combination (Default for SOAP::WSDL::Envelope).
164              
165             =back
166              
167             =head1 LICENSE AND COPYRIGHT
168              
169             Copyright 2004-2007 Martin Kutter.
170              
171             This file is part of SOAP-WSDL. You may distribute/modify it under the same
172             terms as perl itself
173              
174             =head1 AUTHOR
175              
176             Martin Kutter Emartin.kutter fen-net.deE
177              
178             =head1 REPOSITORY INFORMATION
179              
180             $Rev: 851 $
181             $LastChangedBy: kutterma $
182             $Id: Element.pm 851 2009-05-15 22:45:18Z kutterma $
183             $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/XSD/Typelib/Element.pm $
184              
185             =cut
186              
187