| 1 | package SOAP::WSDL::Generator::Template::Plugin::XSD; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Class::Std::Fast::Storable constructor => 'none'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = 3.004; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | my %namespace_prefix_map_of :ATTR(:name<namespace_prefix_map> :default<{}>); | |||||||||||||||||||||||||||
| 10 | 1 | my %namespace_map_of :ATTR(:name<namespace_map> :default<{}>); | |||||||||||||||||||||||||||
| 11 | 1 | my %prefix_of :ATTR(:name<prefix> :default<()>); | |||||||||||||||||||||||||||
| 12 | 1 | my %prefix_resolver_of :ATTR(:name<prefix_resolver> :default<()>); | |||||||||||||||||||||||||||
| 13 | 1 | my %definitions_of :ATTR(:name<definitions> :default<()>); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # create a singleton | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub load { # called as MyPlugin->load($context) | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | my ($class, $context, @arg_from) = @_; | |||||||||||||||||||||||||||
| 19 | 0 | my $stash = $context->stash(); | |||||||||||||||||||||||||||
| 20 | 0 | my $self = bless \do { my $o = Class::Std::Fast::ID() }, $class; | |||||||||||||||||||||||||||
| 21 | 0 | $self->set_prefix_resolver( $stash->{ context }->{ prefix_resolver }); | |||||||||||||||||||||||||||
| 22 | 0 | $self->set_definitions( $stash->{ definitions }); | |||||||||||||||||||||||||||
| 23 | 0 | return $self; # returns 'MyPlugin' | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return shift if ref $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my ($class, $arg_ref) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | my $self = bless \do { my $o = Class::Std::Fast::ID() }, $class; | |||||||||||||||||||||||||||
| 32 | 0 | $self->set_prefix_resolver( $arg_ref->{ prefix_resolver }); | |||||||||||||||||||||||||||
| 33 | 0 | $self->set_definitions( $arg_ref->{ definitions }); | |||||||||||||||||||||||||||
| 34 | 0 | return $self; # returns 'MyPlugin' | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _get_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_get_prefix: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $type, $node) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $namespace = defined ($node) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 40 | ? ref($node) | ||||||||||||||||||||||||||||
| 41 | ? $node->get_targetNamespace() | ||||||||||||||||||||||||||||
| 42 | : $node | ||||||||||||||||||||||||||||
| 43 | : undef; | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return $self->get_prefix_resolver()->resolve_prefix( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | $type, | ||||||||||||||||||||||||||||
| 46 | $namespace, | ||||||||||||||||||||||||||||
| 47 | ref($node) | ||||||||||||||||||||||||||||
| 48 | ? $node | ||||||||||||||||||||||||||||
| 49 | : undef | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub create_xsd_name { | ||||||||||||||||||||||||||
|
Subroutine
create_xsd_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | confess "no node $node" if not defined($node) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $node or $node eq ""
MC/DC0%0/2
not defined $node or $node eq ""
not defined $node
$node eq ""
Truth table0%0/3
not(A) or B
A= not defined $nodeB= $node eq ""
| |||||||||||||||||||||||||||||
| 56 | or $node eq ""; | ||||||||||||||||||||||||||||
| 57 | 0 | my $name = $self->_resolve_prefix($node) #. '::' | |||||||||||||||||||||||||||
| 58 | . $node->get_name(); | ||||||||||||||||||||||||||||
| 59 | 0 | return $self->perl_name( $name ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub create_typemap_name { | ||||||||||||||||||||||||||
|
Subroutine
create_typemap_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||
| 64 | 0 | my $name = $self->_get_prefix('typemap') #. '::' | |||||||||||||||||||||||||||
| 65 | . $node->get_name(); | ||||||||||||||||||||||||||||
| 66 | 0 | return $self->perl_name( $name ); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub create_server_name { | ||||||||||||||||||||||||||
|
Subroutine
create_server_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $server, $port) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | my $port_name = $port->get_name(); | |||||||||||||||||||||||||||
| 72 | 0 | $port_name =~s{\A (?:.+)\. ([^\.]+) \z}{$1}x; | |||||||||||||||||||||||||||
| 73 | 0 | my $name = join( q{}, | |||||||||||||||||||||||||||
| 74 | $self->_get_prefix('server', $server), | ||||||||||||||||||||||||||||
| 75 | join( '::', $server->get_name(), $port_name) | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | 0 | return $self->perl_name( $name ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub create_interface_name { | ||||||||||||||||||||||||||
|
Subroutine
create_interface_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ($self, $server, $port) = @_; | |||||||||||||||||||||||||||
| 82 | 0 | my $port_name = $port->get_name(); | |||||||||||||||||||||||||||
| 83 | 0 | $port_name =~s{\A (?:.+)\. ([^\.]+) \z}{$1}x; | |||||||||||||||||||||||||||
| 84 | 0 | my $name = join( q{}, | |||||||||||||||||||||||||||
| 85 | $self->_get_prefix('interface', $server), | ||||||||||||||||||||||||||||
| 86 | join( '::', $server->get_name(), $port_name ) | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | 0 | return $self->perl_name( $name ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub _resolve_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_resolve_prefix: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $node) = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($node->isa('SOAP::WSDL::XSD::Builtin')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | return $self->_get_prefix('type', $node) | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( $node->isa('SOAP::WSDL::XSD::SimpleType') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->isa("SOAP::WSDL::XSD::SimpleType") or $node->isa("SOAP::WSDL::XSD::ComplexType")
MC/DC0%0/2
$node->isa("SOAP::WSDL::XSD::SimpleType") or $node->isa("SOAP::WSDL::XSD::ComplexType")
$node->isa("SOAP::WSDL::XSD::SimpleType")
$node->isa("SOAP::WSDL::XSD::ComplexType")
Truth table0%0/3
A or B
A= $node->isa("SOAP::WSDL::XSD::SimpleType")B= $node->isa("SOAP::WSDL::XSD::ComplexType")
| |||||||||||||||||||||||||||||
| 98 | or $node->isa('SOAP::WSDL::XSD::ComplexType') | ||||||||||||||||||||||||||||
| 99 | ) { | ||||||||||||||||||||||||||||
| 100 | 0 | return $self->_get_prefix('type', $node); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( $node->isa('SOAP::WSDL::XSD::Element') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | return $self->_get_prefix('element', $node); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( $node->isa('SOAP::WSDL::XSD::Attribute') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | return $self->_get_prefix('attribute', $node); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub perl_name { | ||||||||||||||||||||||||||
|
Subroutine
perl_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 113 | 0 | $name =~s{\-}{_}xmsg; | |||||||||||||||||||||||||||
| 114 | 0 | $name =~s{\.}{::}xmsg; | |||||||||||||||||||||||||||
| 115 | 0 | return $name; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub perl_var_name { | ||||||||||||||||||||||||||
|
Subroutine
perl_var_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 120 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 121 | 0 | $name =~s{\-}{_}xmsg; | |||||||||||||||||||||||||||
| 122 | 0 | $name =~s{\.}{__}xmsg; | |||||||||||||||||||||||||||
| 123 | 0 | return $name; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub create_subpackage_name { | ||||||||||||||||||||||||||
|
Subroutine
create_subpackage_name: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | my $arg_ref = shift; | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $type = ref $arg_ref eq 'HASH' ? $arg_ref->{ value } : $arg_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my @name_from = $type->get_name() || (); ; | ||||||||||||||||||||||||||
|
Condition0%0/3
$type->get_name || ()
MC/DC0%0/2
$type->get_name || ()
$type->get_name
()
Truth table0%0/3
A || B
A= $type->get_nameB= ()
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # search for top node in tree (the one directly below the Schema) | ||||||||||||||||||||||||||||
| 134 | 0 | my $parent = $type; | |||||||||||||||||||||||||||
| 135 | 0 | my $top_node = $parent; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (! $parent->get_parent()->isa('SOAP::WSDL::XSD::Schema') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | NAMES: while ($parent = $parent->get_parent()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | $top_node = $parent; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | last NAMES if $parent->get_parent()->isa('SOAP::WSDL::XSD::Schema'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | # skip empty names - atomic types have no name... | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | unshift @name_from, $parent->get_name() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | if $parent->get_name(); | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | # create name for top node | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | die "No top node found" if not defined $top_node; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | my $top_node_name = $self->create_xsd_name($top_node); | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $package_name = join('::_', $top_node_name , (@name_from) ? join('::', @name_from) : () ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # replace dots by :: in name - subpackage names may include dots, too | ||||||||||||||||||||||||||||
| 151 | 0 | $package_name =~s{\.}{::}xg; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | return $package_name; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub create_xmlattr_name { | ||||||||||||||||||||||||||
|
Subroutine
create_xmlattr_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 0 | return join '::', shift->create_subpackage_name(shift), 'XmlAttr'; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub element_name { | ||||||||||||||||||||||||||
|
Subroutine
element_name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | confess "no element object" unless blessed $element; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | my $name = $element->get_name(); | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | if (! $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | while (my $ref = $element->get_ref()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | $element = $self->get_definitions()->first_types() | |||||||||||||||||||||||||||
| 170 | ->find_element($element->expand( $ref ) ); | ||||||||||||||||||||||||||||
| 171 | 0 | $name = $element->get_name(); | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | last if ($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 0 | return $name; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1 | 1; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =pod | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =head1 NAME | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | SOAP::WSDL::Generator::Template::Plugin::XSD - Template plugin for the XSD generator | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 METHODS | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head2 perl_name | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | XSD.perl_name(element.get_name); | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | Converts a XML name into a valid perl name (valid for subroutines, variables | ||||||||||||||||||||||||||||
| 193 | or the like). | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | perl_name takes a crude approach by just replacing . and - (dot and dash) | ||||||||||||||||||||||||||||
| 196 | with a underscore. This may or may not be sufficient, and may or may not | ||||||||||||||||||||||||||||
| 197 | provoke collisions in your XML names. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Copyright 2008 Martin Kutter. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | This file is part of SOAP-WSDL. You may distribute/modify it under the same | ||||||||||||||||||||||||||||
| 204 | terms as perl itself | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Martin Kutter E<lt>martin.kutter fen-net.deE<gt> | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head1 REPOSITORY INFORMATION | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | $Rev: 564 $ | ||||||||||||||||||||||||||||
| 213 | $LastChangedBy: kutterma $ | ||||||||||||||||||||||||||||
| 214 | $Id: ComplexType.pm 564 2008-02-23 13:31:39Z kutterma $ | ||||||||||||||||||||||||||||
| 215 | $HeadURL: http://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/XSD/Typelib/ComplexType.pm $ | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||