« blib/lib/SOAP/WSDL/XSD/Typelib/Builtin/dateTime.pm
↑ Summary
blib/lib/SOAP/WSDL/Deserializer/SOM.pm »
| 1 | package SOAP::WSDL::XSD::Typelib::Element; | ||||||||||||||||||||
| 2 | 15 | ▶ | use strict; use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 15 | ▶ | use Class::Std::Fast::Storable constructor => 'none'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 15 | our $VERSION = 3.004; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 15 | my %NAME; | |||||||||||||||||||
| 8 | my %NILLABLE; | ||||||||||||||||||||
| 9 | 15 | my %REF; | |||||||||||||||||||
| 10 | 15 | my %MIN_OCCURS; | |||||||||||||||||||
| 11 | 15 | 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 | 15 | 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 | 15 | ▶ | no strict qw(refs); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 15 | ▶ | while (my ($name, $value) = each %method_lookup ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 75 | ▶ | *{ "__set$name" } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 31 | 114 | ▶ | @_ or die "Cannot call __set$name without parameter"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 113 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition100%3/3
ref $_[0] || $_[0]
MC/DC100%2/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table100%3/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 33 | 113 | $value->{ $class } = $_[1]; | |||||||||||||||||||
| 34 | 75 | }; | |||||||||||||||||||
| 35 | 75 | ▶ | *{ "__get$name" } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 36 | 6 | ▶ | @_ or die "Cannot call __set$name as function"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 5 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition100%3/3
ref $_[0] || $_[0]
MC/DC100%2/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table100%3/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 38 | 5 | return $value->{ $class }; | |||||||||||||||||||
| 39 | 75 | }; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # use $_[0] and $_[1] for speed. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 27 | ▶ | sub start_tag { | ||||||||||||||||||
|
Subroutine
start_tag: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | # my ($self, $opt, $value) = @_; | ||||||||||||||||||||
| 48 | 27 | ▶ | my $ending = ($_[1]->{ empty }) ? '/>' : '>'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 27 | my @attr_from = (); | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 27 | ▶ | if ($_[1]->{ nil }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 3 | ▶ | return q{} if not $NILLABLE{ ref $_[0] }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 2 | push @attr_from, q{ xsi:nil="true"}; | |||||||||||||||||||
| 54 | 2 | $ending = '/>'; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 26 | ▶ | if (delete $_[1]->{qualified}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 14 | push @attr_from, q{ xmlns="} . $_[0]->get_xmlns() . q{"}; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 26 | 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 | 26 | ▶ | return join q{}, "<$_[1]->{ name }" , @attr_from , $ending if $_[1]->{ name }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 16 | 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 "</$opt->{name}>" if $opt->{name}; | ||||||||||||||||||||
| 74 | # return "</"$NAME{$class}>"; | ||||||||||||||||||||
| 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 | 22 | ▶ | sub end_tag { | ||||||||||||||||||
|
Subroutine
end_tag: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 80 | 22 | ▶ | return "</$_[1]->{name}>" if $_[1]->{name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 12 | return "</$NAME{ ref $_[0] }>"; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 15 | 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 | <element name="MyElement" type="xsd:string" nillable="1" | ||||||||||||||||||||
| 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 | <element name="MyElement2" ref="tns:MyElement"/> | ||||||||||||||||||||
| 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 definitely 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 E<lt>martin.kutter fen-net.deE<gt> | ||||||||||||||||||||
| 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 | |||||||||||||||||||||