line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package W3C::SOAP::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2012-06-01 12:15:15 |
4
|
|
|
|
|
|
|
# Create by: dev |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
20
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
157
|
|
10
|
5
|
|
|
5
|
|
19
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
128
|
|
11
|
5
|
|
|
5
|
|
18
|
use version; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
21
|
|
12
|
5
|
|
|
5
|
|
217
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
231
|
|
13
|
5
|
|
|
5
|
|
23
|
use Scalar::Util; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
153
|
|
14
|
5
|
|
|
5
|
|
19
|
use List::Util; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
227
|
|
15
|
5
|
|
|
5
|
|
19
|
use Data::Dumper qw/Dumper/; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
190
|
|
16
|
5
|
|
|
5
|
|
19
|
use English qw/ -no_match_vars /; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
19
|
|
17
|
5
|
|
|
5
|
|
3175
|
use W3C::SOAP::WSDL::Utils; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
53
|
|
18
|
5
|
|
|
5
|
|
2899
|
use W3C::SOAP::WSDL::Meta::Method; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
81
|
|
19
|
5
|
|
|
5
|
|
2724
|
use URI; |
|
5
|
|
|
|
|
15231
|
|
|
5
|
|
|
|
|
3041
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
22
|
|
|
|
|
|
|
as_is => [qw/split_ns xml_error normalise_ns cmp_ns ns2module/], |
23
|
|
|
|
|
|
|
with_meta => ['operation'], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = version->new('0.11'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub split_ns { |
29
|
0
|
|
|
0
|
1
|
|
my ($tag) = @_; |
30
|
0
|
0
|
|
|
|
|
confess "No XML tag passed to split!\n" unless defined $tag; |
31
|
0
|
|
|
|
|
|
my ($ns, $name) = split /:/xms, $tag, 2; |
32
|
0
|
0
|
|
|
|
|
return $name ? ($ns, $name) : ('', $ns); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub normalise_ns { |
36
|
0
|
|
|
0
|
1
|
|
my ($ns) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $uri = URI->new($ns); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ( $uri->can('host') ) { |
41
|
0
|
|
|
|
|
|
$uri->host(lc $uri->host); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return "$uri"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ns2module { |
48
|
0
|
|
|
0
|
1
|
|
my ($ns) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $uri = URI->new($ns); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# URI's which have a host an a path are converted Java style name spacing |
53
|
0
|
0
|
0
|
|
|
|
if ( $uri->can('host') && $uri->can('path') ) { |
54
|
0
|
|
|
|
|
|
my $module |
55
|
|
|
|
|
|
|
= join '::', |
56
|
0
|
|
|
|
|
|
reverse map { ucfirst $_} |
57
|
0
|
|
|
|
|
|
map { lc $_ } |
58
|
0
|
|
|
|
|
|
map { s/\W/_/gxms; $_ } ## no critic |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
split /[.]/xms, $uri->host; |
60
|
0
|
|
|
|
|
|
$module .= join '::', |
61
|
0
|
|
|
|
|
|
map { s/\W/_/gxms; $_ } ## no critic |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
split m{/}xms, $uri->path; |
63
|
0
|
|
|
|
|
|
return $module; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# other URI's are just made safe as a perl module name. |
67
|
0
|
|
|
|
|
|
$ns =~ s{://}{::}xms; |
68
|
0
|
|
|
|
|
|
$ns =~ s{([^:]:)([^:])}{$1:$2}gxms; |
69
|
0
|
|
|
|
|
|
$ns =~ s{[^\w:]+}{_}gxms; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $ns; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub cmp_ns { |
75
|
0
|
|
|
0
|
1
|
|
my ($ns1, $ns2) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return normalise_ns($ns1) eq normalise_ns($ns2); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub xml_error { |
81
|
0
|
|
|
0
|
1
|
|
my ($node) = @_; |
82
|
0
|
|
|
|
|
|
my @lines = split /\r?\n/xms, $node->toString; |
83
|
0
|
|
|
|
|
|
my $indent = ''; |
84
|
0
|
0
|
0
|
|
|
|
if ( $lines[0] !~ /^\s+/xms && $lines[-1] =~ /^(\s+)/xms ) { |
85
|
0
|
|
|
|
|
|
$indent = $1; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
my $error = $indent . $node->toString."\n at "; |
88
|
0
|
0
|
|
|
|
|
$error .= "line - ".$node->line_number.' ' if $node->line_number; |
89
|
0
|
|
|
|
|
|
$error .= "path - ".$node->nodePath; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $error; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
W3C::SOAP::Utils - Utility functions to be used with C<W3C::SOAP> modules |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 VERSION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This documentation refers to W3C::SOAP::Utils version 0.11. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use W3C::SOAP::Utils; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# splits tags with an optional XML namespace prefix |
111
|
|
|
|
|
|
|
my ($namespace, $tag) = split_ns('xs:thing'); |
112
|
|
|
|
|
|
|
# $namespace = xs |
113
|
|
|
|
|
|
|
# $tag = thing |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Utility Functions |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SUBROUTINES |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 4 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<split_ns ($name)> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Splits an XML tag's namespace from the tag name |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item C<normalise_ns ($ns)> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Creates a normalized XML name space string (ie lower cases the host part of |
130
|
|
|
|
|
|
|
the name space) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item C<ns2module ($ns)> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Takes the XML namespace C<$ns> and coverts it to a module name, if it is a |
135
|
|
|
|
|
|
|
"normal" URI the module name is got by reversing the order of the domain |
136
|
|
|
|
|
|
|
parts and joining that with any directory parts (setting default Perl module |
137
|
|
|
|
|
|
|
capitalization along the way) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
eg http://www.example.com/some/path => Com::Example::Www::Some::Path |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
If the URI doesn't have a host part then URI is split on the non-word |
142
|
|
|
|
|
|
|
characters and similarly rejoined |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
eg uri:thing.other/unknown => Uri::Thing::Other::Unknown |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C<cmp_ns ($ns1, $ns2)> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Compare two namespaces (with normalized host parts lower cased) |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item C<xml_error ($xml_node)> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Pretty format the C<$xml_node> for an error message |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 MOOSE HELPERS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item C<operation ($name, %optisns)> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
See L<W3C::SOAP::WSDL::Utils> for details using it from this module is deprecated |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
There are no known bugs in this module. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Please report problems to Ivan Wills - (ivan.wills@gmail.com) |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Patches are welcome. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
189
|
|
|
|
|
|
|
All rights reserved. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
192
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
193
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
194
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
195
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |