File Coverage

blib/lib/W3C/SOAP/WSDL/Document.pm
Criterion Covered Total %
statement 22 24 91.6
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 30 32 93.7


line stmt bran cond sub pod time code
1             package W3C::SOAP::WSDL::Document;
2              
3             # Created on: 2012-05-27 18:57:29
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   1446 use Moose;
  1         2  
  1         6  
10 1     1   4658 use warnings;
  1         2  
  1         23  
11 1     1   3 use version;
  1         2  
  1         6  
12 1     1   50 use Carp;
  1         2  
  1         53  
13 1     1   5 use Data::Dumper qw/Dumper/;
  1         1  
  1         38  
14 1     1   4 use English qw/ -no_match_vars /;
  1         1  
  1         10  
15 1     1   367 use Path::Class;
  1         2  
  1         47  
16 1     1   241 use XML::LibXML;
  0            
  0            
17             use W3C::SOAP::XSD::Document;
18             use W3C::SOAP::WSDL::Document::Binding;
19             use W3C::SOAP::WSDL::Document::Message;
20             use W3C::SOAP::WSDL::Document::PortType;
21             use W3C::SOAP::WSDL::Document::Service;
22              
23             extends 'W3C::SOAP::Document';
24              
25             our $VERSION = version->new('0.11');
26              
27             has messages => (
28             is => 'rw',
29             isa => 'ArrayRef[W3C::SOAP::WSDL::Document::Message]',
30             builder => '_messages',
31             lazy => 1,
32             );
33             has message => (
34             is => 'rw',
35             isa => 'HashRef[W3C::SOAP::WSDL::Document::Message]',
36             builder => '_message',
37             lazy => 1,
38             weak_ref => 1,
39             );
40             has port_types => (
41             is => 'rw',
42             isa => 'ArrayRef[W3C::SOAP::WSDL::Document::PortType]',
43             builder => '_port_types',
44             lazy => 1,
45             );
46             has port_type => (
47             is => 'rw',
48             isa => 'HashRef[W3C::SOAP::WSDL::Document::PortType]',
49             builder => '_port_type',
50             lazy => 1,
51             weak_ref => 1,
52             );
53             has bindings => (
54             is => 'rw',
55             isa => 'ArrayRef[W3C::SOAP::WSDL::Document::Binding]',
56             builder => '_bindings',
57             lazy => 1,
58             );
59             has binding => (
60             is => 'rw',
61             isa => 'HashRef[W3C::SOAP::WSDL::Document::Binding]',
62             builder => '_binding',
63             lazy => 1,
64             weak_ref => 1,
65             );
66             has services => (
67             is => 'rw',
68             isa => 'ArrayRef[W3C::SOAP::WSDL::Document::Service]',
69             builder => '_services',
70             lazy => 1,
71             );
72             has service => (
73             is => 'rw',
74             isa => 'HashRef[W3C::SOAP::WSDL::Document::Service]',
75             builder => '_service',
76             lazy => 1,
77             weak_ref => 1,
78             );
79             has policies => (
80             is => 'rw',
81             isa => 'ArrayRef[W3C::SOAP::WSDL::Document::Policy]',
82             builder => '_policies',
83             lazy => 1,
84             weak_ref => 1,
85             );
86             has policy => (
87             is => 'rw',
88             isa => 'HashRef[W3C::SOAP::WSDL::Document::Policy]',
89             builder => '_policy',
90             lazy => 1,
91             weak_ref => 1,
92             );
93             has schemas => (
94             is => 'rw',
95             isa => 'ArrayRef[W3C::SOAP::XSD::Document]',
96             builder => '_schemas',
97             lazy => 1,
98             );
99             has schema => (
100             is => 'rw',
101             isa => 'HashRef[W3C::SOAP::XSD::Document]',
102             builder => '_schema',
103             lazy => 1,
104             weak_ref => 1,
105             );
106              
107             sub _messages {
108             my ($self) = @_;
109             my @messages;
110             my @nodes = $self->xpc->findnodes('//wsdl:message');
111              
112             for my $node (@nodes) {
113             push @messages, W3C::SOAP::WSDL::Document::Message->new(
114             document => $self,
115             node => $node,
116             );
117             }
118              
119             return \@messages;
120             }
121              
122             sub _message {
123             my ($self) = @_;
124             my %message;
125             for my $message ( @{ $self->messages }) {
126             $message{$message->name} = $message;
127             }
128              
129             return \%message;
130             }
131              
132             sub _port_types {
133             my ($self) = @_;
134             my @port_types;
135             my @nodes = $self->xpc->findnodes('//wsdl:portType');
136              
137             for my $node (@nodes) {
138             push @port_types, W3C::SOAP::WSDL::Document::PortType->new(
139             document => $self,
140             node => $node,
141             );
142             }
143              
144             return \@port_types;
145             }
146              
147             sub _port_type {
148             my ($self) = @_;
149             my %port_type;
150             for my $port_type ( @{ $self->port_type }) {
151             $port_type{$port_type->name} = $port_type;
152             }
153              
154             return \%port_type;
155             }
156              
157             sub _bindings {
158             my ($self) = @_;
159             my @bindings;
160             my @nodes = $self->xpc->findnodes('//wsdl:binding');
161              
162             for my $node (@nodes) {
163             push @bindings, W3C::SOAP::WSDL::Document::Binding->new(
164             document => $self,
165             node => $node,
166             );
167             }
168              
169             return \@bindings;
170             }
171              
172             sub _binding {
173             my ($self) = @_;
174             my %binding;
175             for my $binding ( @{ $self->binding }) {
176             $binding{$binding->name} = $binding;
177             }
178              
179             return \%binding;
180             }
181              
182             sub _services {
183             my ($self) = @_;
184             my @services;
185             my @nodes = $self->xpc->findnodes('//wsdl:service');
186              
187             for my $node (@nodes) {
188             push @services, W3C::SOAP::WSDL::Document::Service->new(
189             document => $self,
190             node => $node,
191             );
192             }
193              
194             return \@services;
195             }
196              
197             sub _service {
198             my ($self) = @_;
199             my %service;
200             for my $service ( @{ $self->service }) {
201             $service{$service->name} = $service;
202             }
203              
204             return \%service;
205             }
206              
207             sub _policies {
208             my ($self) = @_;
209             my @policies;
210             my @nodes = $self->xpc->findnodes('/*/wsp:Policy');
211              
212             for my $node (@nodes) {
213             push @policies, W3C::SOAP::WSDL::Document::Policy->new(
214             document => $self,
215             node => $node,
216             );
217             }
218              
219             return \@policies;
220             }
221              
222             sub _policy {
223             my ($self) = @_;
224             my %service;
225             for my $service ( @{ $self->service }) {
226             $service{$service->sec_id} = $service;
227             }
228              
229             return \%service;
230             }
231              
232             sub _schemas {
233             my ($self) = @_;
234             my @schemas;
235             my @nodes = $self->xpc->findnodes('//wsdl:types/*');
236              
237             for my $node (@nodes) {
238             next if $node->getAttribute('namespace') && $node->getAttribute('namespace') eq 'http://www.w3.org/2001/XMLSchema';
239              
240             # merge document namespaces into the schema's tags
241             my $doc = $self->xml->getDocumentElement;
242             my @attribs = $doc->getAttributes;
243             for my $ns ( grep {$_->name =~ /^xmlns:/ && !$node->getAttribute($_->name)} @attribs ) {
244             $node->setAttribute( $ns->name, 'value' );
245             $node->setAttribute( $ns->name, $ns->value );
246             }
247              
248             my @args;
249             if ( $self->has_module_base ) {
250             my $base = $self->module_base;
251             $base =~ s/WSDL/XSD/;
252             $base .= '::XSD' if $base !~ /XSD/;
253             push @args, ( module_base => $base );
254             }
255              
256             push @schemas, W3C::SOAP::XSD::Document->new(
257             string => $node->toString,
258             ns_module_map => $self->ns_module_map,
259             @args,
260             );
261             $schemas[-1]->location($self->location);
262             $schemas[-1]->target_namespace;
263             }
264              
265             return \@schemas;
266             }
267              
268             sub _schema {
269             my ($self) = @_;
270             my %schema;
271             for my $schema ( @{ $self->schemas }) {
272             $schema{$schema->target_namespace} = $schema;
273             }
274              
275             return \%schema;
276             }
277              
278             sub get_nsuri {
279             my ($self, $ns) = @_;
280             my ($node) = $self->xpc->findnodes("//namespace::*[name()='$ns']");
281             return $node->value;
282             }
283              
284             sub xsd_modules {
285             my ($self) = @_;
286             my %modules;
287              
288             for my $service (@{ $self->services }) {
289             for my $port (@{ $service->ports }) {
290             for my $operation (@{ $port->binding->operations }) {
291             if ( $operation->port_type->outputs->[0] && $operation->port_type->outputs->[0]->message->element ) {
292             $modules{$operation->port_type->outputs->[0]->message->element->module}++;
293             }
294             }
295             }
296             }
297              
298             return ( sort keys %modules );
299             }
300              
301             1;
302              
303             __END__
304              
305             =head1 NAME
306              
307             W3C::SOAP::WSDL::Document - Object to represent a WSDL Document
308              
309             =head1 VERSION
310              
311             This documentation refers to W3C::SOAP::WSDL::Document version 0.11.
312              
313             =head1 SYNOPSIS
314              
315             use W3C::SOAP::WSDL::Document;
316              
317             # Brief but working code example(s) here showing the most common usage(s)
318             # This section will be as far as many users bother reading, so make it as
319             # educational and exemplary as possible.
320              
321             =head1 DESCRIPTION
322              
323             Top level look at a WSDL, supplies access to messages, services etc defined
324             in the WSDL.
325              
326             =head1 SUBROUTINES/METHODS
327              
328             =over 4
329              
330             =item C<get_nsuri ()>
331              
332             =item C<xsd_modules ()>
333              
334             =back
335              
336             =head1 DIAGNOSTICS
337              
338             =head1 CONFIGURATION AND ENVIRONMENT
339              
340             =head1 DEPENDENCIES
341              
342             =head1 INCOMPATIBILITIES
343              
344             =head1 BUGS AND LIMITATIONS
345              
346             There are no known bugs in this module.
347              
348             Please report problems to Ivan Wills (ivan.wills@gmail.com).
349              
350             Patches are welcome.
351              
352             =head1 AUTHOR
353              
354             Ivan Wills - (ivan.wills@gmail.com)
355              
356             =head1 LICENSE AND COPYRIGHT
357              
358             Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
359             All rights reserved.
360              
361             This module is free software; you can redistribute it and/or modify it under
362             the same terms as Perl itself. See L<perlartistic>. This program is
363             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
364             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
365             PARTICULAR PURPOSE.
366              
367             =cut