| 1 | package W3C::SOAP::Document; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2012-05-27 19:26:43 | ||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Carp qw/carp croak cluck confess longmess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use W3C::SOAP::Utils qw/normalise_ns ns2module/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use W3C::SOAP::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | our $VERSION = 0.13; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | has string => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | 7 | has location => ( | |||||||||||||||||||||||||||
| 29 | is => 'rw', | ||||||||||||||||||||||||||||
| 30 | isa => 'Str', | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | 7 | has xml => ( | |||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => 'XML::LibXML::Document', | ||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | 7 | has xpc => ( | |||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||
| 39 | isa => 'XML::LibXML::XPathContext', | ||||||||||||||||||||||||||||
| 40 | builder => '_xpc', | ||||||||||||||||||||||||||||
| 41 | clearer => 'clear_xpc', | ||||||||||||||||||||||||||||
| 42 | predicate => 'has_xpc', | ||||||||||||||||||||||||||||
| 43 | lazy => 1, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | 7 | has target_namespace => ( | |||||||||||||||||||||||||||
| 46 | is => 'rw', | ||||||||||||||||||||||||||||
| 47 | isa => 'Str', | ||||||||||||||||||||||||||||
| 48 | builder => '_target_namespace', | ||||||||||||||||||||||||||||
| 49 | predicate => 'has_target_namespace', | ||||||||||||||||||||||||||||
| 50 | lazy => 1, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | has ns_module_map => ( | ||||||||||||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||||||||||||
| 54 | isa => 'HashRef[Str]', | ||||||||||||||||||||||||||||
| 55 | required => 1, | ||||||||||||||||||||||||||||
| 56 | predicate => 'has_ns_module_map', | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | default => sub{{}}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 7 | ); | |||||||||||||||||||||||||||
| 59 | 7 | has module => ( | |||||||||||||||||||||||||||
| 60 | is => 'rw', | ||||||||||||||||||||||||||||
| 61 | isa => 'Str', | ||||||||||||||||||||||||||||
| 62 | predicate => 'has_module', | ||||||||||||||||||||||||||||
| 63 | builder => '_module', | ||||||||||||||||||||||||||||
| 64 | lazy => 1, | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | 7 | has module_base => ( | |||||||||||||||||||||||||||
| 67 | is => 'rw', | ||||||||||||||||||||||||||||
| 68 | isa => 'Str', | ||||||||||||||||||||||||||||
| 69 | predicate => 'has_module_base', | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 73 | 18 | ▶ | my ($orig, $class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.9
| |||||||||||||||||||||||||||||
| 74 | 18 | ▶ | my $args | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 75 | = !@args ? {} | ||||||||||||||||||||||||||||
| 76 | : @args == 1 ? $args[0] | ||||||||||||||||||||||||||||
| 77 | : {@args}; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 18 | ▶ | delete $args->{module_base} if ! defined $args->{module_base}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 18 | ▶ | if ( $args->{string} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 82 | try { | ||||||||||||||||||||||||||||
| 83 | 4 | ▶ | $args->{xml} = XML::LibXML->load_xml(string => $args->{string}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | catch { | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | chomp $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 0 | W3C::SOAP::Exception::XML->throw( error => $_, faultstring => $_ ); | |||||||||||||||||||||||||||
| 88 | 4 | }; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | elsif ( $args->{location} ) { | ||||||||||||||||||||||||||||
| 91 | try { | ||||||||||||||||||||||||||||
| 92 | 14 | ▶ | $args->{xml} = XML::LibXML->load_xml(location => $args->{location}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | catch { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | chomp $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 96 | 0 | W3C::SOAP::Exception::XML->throw( error => $_, faultstring => $args->{location} ); | |||||||||||||||||||||||||||
| 97 | 14 | }; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 18 | return $class->$orig($args); | |||||||||||||||||||||||||||
| 101 | 7 | }; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub _xpc { | ||||||||||||||||||||||||||||
| 104 | 22 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_xpc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 22 | my $xpc = XML::LibXML::XPathContext->new($self->xml); | |||||||||||||||||||||||||||
| 106 | 22 | $xpc->registerNs(xs => 'http://www.w3.org/2001/XMLSchema'); | |||||||||||||||||||||||||||
| 107 | 22 | $xpc->registerNs(xsd => 'http://www.w3.org/2001/XMLSchema'); | |||||||||||||||||||||||||||
| 108 | 22 | $xpc->registerNs(wsdl => 'http://schemas.xmlsoap.org/wsdl/'); | |||||||||||||||||||||||||||
| 109 | 22 | $xpc->registerNs(wsp => 'http://schemas.xmlsoap.org/ws/2004/09/policy'); | |||||||||||||||||||||||||||
| 110 | 22 | $xpc->registerNs(wssp => 'http://www.bea.com/wls90/security/policy'); | |||||||||||||||||||||||||||
| 111 | 22 | $xpc->registerNs(soap => 'http://schemas.xmlsoap.org/wsdl/soap/'); | |||||||||||||||||||||||||||
| 112 | 22 | $xpc->registerNs(soap12 => 'http://schemas.xmlsoap.org/wsdl/soap12/'); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 22 | return $xpc; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 7 | my $anon = 0; | |||||||||||||||||||||||||||
| 118 | sub _target_namespace { | ||||||||||||||||||||||||||||
| 119 | 18 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_target_namespace: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||
| 120 | 18 | my $ns = $self->xml->getDocumentElement->getAttribute('targetNamespace'); | |||||||||||||||||||||||||||
| 121 | 18 | my $xpc = $self->xpc; | |||||||||||||||||||||||||||
| 122 | 18 | ▶ | $xpc->registerNs(ns => $ns) if $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 18 | ▶ | $ns ||= $self->location || 'NsAnon' . $anon++; | ||||||||||||||||||||||||||
|
Condition20%1/5
$ns ||= $self->location || 'NsAnon' . $anon++
$self->location || 'NsAnon' . $anon++
MC/DC0%0/2
$ns ||= $self->location || 'NsAnon' . $anon++
$ns
$self->location
Truth table33%1/3
A ||= B
A= $nsB= $self->location
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 18 | return $ns; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub _module { | ||||||||||||||||||||||||||||
| 130 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_module: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 12 | return $self->get_module_name( $self->target_namespace ); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub get_module_name { | ||||||||||||||||||||||||||||
| 135 | 288 | ▶ | my ($self, $ns) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_module_name: called CC=7 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 288 | ▶ | confess "No namespace given!" if !defined $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # namespace may be empty but map must be a module | ||||||||||||||||||||||||||||
| 139 | 288 | ▶ | if ( ! $self->ns_module_map->{normalise_ns($ns)} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # construct module name if we have a base name | ||||||||||||||||||||||||||||
| 142 | 7 | ▶ | if ( $self->has_module_base ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 7 | $self->ns_module_map->{normalise_ns($ns)} | |||||||||||||||||||||||||||
| 144 | = $self->module_base . '::' . ns2module($ns); | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # copy the unnormalised module name if we have one | ||||||||||||||||||||||||||||
| 148 | 7 | ▶ | if ( ! $self->ns_module_map->{normalise_ns($ns)} && $self->ns_module_map->{$ns} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->ns_module_map->{normalise_ns($ns)} and $self->ns_module_map->{$ns}
MC/DC0%0/2
not $self->ns_module_map->{normalise_ns($ns)} and $self->ns_module_map->{$ns}
not $self->ns_module_map->{normalise_ns($ns)}
$self->ns_module_map->{$ns}
Truth table33%1/3
not(A) and B
A= not $self->ns_module_map->{normalise_ns($ns)}B= $self->ns_module_map->{$ns}
| |||||||||||||||||||||||||||||
| 149 | 0 | $self->ns_module_map->{normalise_ns($ns)} = $self->ns_module_map->{$ns}; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # all else fails throw an error | ||||||||||||||||||||||||||||
| 153 | 7 | ▶ | if ( ! $self->ns_module_map->{normalise_ns($ns)} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | confess "No mapping specified for the namespace $ns!\n" | |||||||||||||||||||||||||||
| 155 | . "If you are using xsd-parser or wsdl-parser try adding to your command\n" | ||||||||||||||||||||||||||||
| 156 | . " -n '$ns=My::NameSpace'\n"; | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 288 | return $self->ns_module_map->{normalise_ns($ns)}; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 7 | 1; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head1 NAME | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | W3C::SOAP::Document - Object to represent an XML Document | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head1 VERSION | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | This documentation refers to W3C::SOAP::Document version 0.13. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | use W3C::SOAP::Document; | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # Instanciate a new document from a string | ||||||||||||||||||||||||||||
| 180 | my $xml = W3C::SOAP::Document( string => $string ); | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # From a url or file | ||||||||||||||||||||||||||||
| 183 | my $xml = W3C::SOAP::Document->new( location => 'http://eg.com/schema.xsd' ); | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | C<W3C::SOAP::Document> takes an XML document from a string/file/url/L<XML::LibXML> | ||||||||||||||||||||||||||||
| 188 | object and parses it to extract the important information about the document. This | ||||||||||||||||||||||||||||
| 189 | the base class for L<W3C::SOAP::XSD::Document> and L<W3C::SOAP::WSDL::Document>. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =over 4 | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =item C<new ( location => ... || string => ... || xml => ... )> | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Creates a new C<W3C::SOAP::Document> object. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =item C<get_module_name ( $namespace )> | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Get the Perl module name for a XML namespace. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =back | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | There are no known bugs in this module. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | Patches are welcome. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||||||||||||||||||||||||||||
| 228 | All rights reserved. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 231 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||||||||||||||||||||
| 232 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||
| 233 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 234 | PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||||||||