| 1 | package SOAP::WSDL::Factory::Transport; | ||||||||||||||||||||||||||||
| 2 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 24 | our $VERSION = 3.004; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 24 | my %registered_transport_of = (); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # Local constants | ||||||||||||||||||||||||||||
| 9 | # Could be made readonly, but that's just for the paranoid... | ||||||||||||||||||||||||||||
| 10 | 24 | my %SOAP_LITE_TRANSPORT_OF = ( | |||||||||||||||||||||||||||
| 11 | ftp => 'SOAP::Transport::FTP', | ||||||||||||||||||||||||||||
| 12 | http => 'SOAP::Transport::HTTP', | ||||||||||||||||||||||||||||
| 13 | https => 'SOAP::Transport::HTTP', | ||||||||||||||||||||||||||||
| 14 | mailto => 'SOAP::Transport::MAILTO', | ||||||||||||||||||||||||||||
| 15 | 'local' => 'SOAP::Transport::LOCAL', | ||||||||||||||||||||||||||||
| 16 | jabber => 'SOAP::Transport::JABBER', | ||||||||||||||||||||||||||||
| 17 | mq => 'SOAP::Transport::MQ', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 24 | my %SOAP_WSDL_TRANSPORT_OF = ( | |||||||||||||||||||||||||||
| 21 | http => 'SOAP::WSDL::Transport::HTTP', | ||||||||||||||||||||||||||||
| 22 | https => 'SOAP::WSDL::Transport::HTTP', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # class methods only | ||||||||||||||||||||||||||||
| 26 | 8 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 8 | my ($class, $scheme, $package) = @_; | |||||||||||||||||||||||||||
| 28 | 8 | ▶ | die "Cannot use reference as scheme" if ref $scheme; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 7 | $registered_transport_of{ $scheme } = $package; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | sub get_transport { | ||||||||||||||||||||||||||
|
Subroutine
get_transport: called CC=11 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 6 | my ($class, $url, %attrs) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 6 | my $scheme = $url; | |||||||||||||||||||||||||||
| 37 | 6 | $scheme =~s{ \:.+$ }{}xm; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | if (defined $registered_transport_of{ $scheme }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 24 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | $registered_transport_of{ $scheme }->can('new') or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$registered_transport_of{$scheme}->can("new") or eval "require $registered_transport_of{$scheme}"
MC/DC100%2/2
$registered_transport_of{$scheme}->can("new") or eval "require $registered_transport_of{$scheme}"
$registered_transport_of{$scheme}->can("new")
eval "require $registered_transport_of{$scheme}"
Truth table100%3/3
A or B
A= $registered_transport_of{$scheme}->can("new")B= eval "require $registered_transport_of{$scheme}"
| |||||||||||||||||||||||||||||
| 43 | eval "require $registered_transport_of{ $scheme }" | ||||||||||||||||||||||||||||
| 44 | or die "Cannot load transport class $registered_transport_of{ $scheme } : $@"; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # try "foo::Client" class first - SOAP::Tranport always requires | ||||||||||||||||||||||||||||
| 47 | # a package withoug the ::Client appended, and then | ||||||||||||||||||||||||||||
| 48 | # instantiates a ::Client object... | ||||||||||||||||||||||||||||
| 49 | # ... pretty weird ... | ||||||||||||||||||||||||||||
| 50 | # ... must be from some time when the max number of files was a | ||||||||||||||||||||||||||||
| 51 | # sparse resource ... | ||||||||||||||||||||||||||||
| 52 | # ... but we've decided to mimic SOAP::Lite... | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | return $registered_transport_of{ $scheme }->new( %attrs ); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # try SOAP::Lite's Transport module - just skip if not require'able | ||||||||||||||||||||||||||||
| 58 | SOAP_Lite: { | ||||||||||||||||||||||||||||
| 59 | 3 | ▶ | if (exists $SOAP_LITE_TRANSPORT_OF{ $scheme }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 24 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | # behaves interestingly different under different versions of perl | ||||||||||||||||||||||||||||
| 62 | # maybe true even if it's not available | ||||||||||||||||||||||||||||
| 63 | 1 | my $protocol_class = $SOAP_LITE_TRANSPORT_OF{ $scheme } . '::Client'; | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | $protocol_class->can('new') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$protocol_class->can("new") or eval "require $SOAP_LITE_TRANSPORT_OF{$scheme}"
MC/DC0%0/2
$protocol_class->can("new") or eval "require $SOAP_LITE_TRANSPORT_OF{$scheme}"
$protocol_class->can("new")
eval "require $SOAP_LITE_TRANSPORT_OF{$scheme}"
Truth table33%1/3
A or B
A= $protocol_class->can("new")B= eval "require $SOAP_LITE_TRANSPORT_OF{$scheme}"
| |||||||||||||||||||||||||||||
| 65 | or eval "require $SOAP_LITE_TRANSPORT_OF{ $scheme }" | ||||||||||||||||||||||||||||
| 66 | or last SOAP_Lite; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # may fail if it's not available | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $transport = eval { $protocol_class->new( %attrs ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | or last SOAP_Lite; | ||||||||||||||||||||||||||||
| 71 | 0 | return $transport; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | ▶ | if (exists $SOAP_WSDL_TRANSPORT_OF{ $scheme }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 24 | ▶ | no strict qw(refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | $SOAP_WSDL_TRANSPORT_OF{ $scheme }->can('new') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$SOAP_WSDL_TRANSPORT_OF{$scheme}->can("new") or eval "require $SOAP_WSDL_TRANSPORT_OF{$scheme}"
MC/DC0%0/2
$SOAP_WSDL_TRANSPORT_OF{$scheme}->can("new") or eval "require $SOAP_WSDL_TRANSPORT_OF{$scheme}"
$SOAP_WSDL_TRANSPORT_OF{$scheme}->can("new")
eval "require $SOAP_WSDL_TRANSPORT_OF{$scheme}"
Truth table33%1/3
A or B
A= $SOAP_WSDL_TRANSPORT_OF{$scheme}->can("new")B= eval "require $SOAP_WSDL_TRANSPORT_OF{$scheme}"
| |||||||||||||||||||||||||||||
| 78 | or eval "require $SOAP_WSDL_TRANSPORT_OF{ $scheme }" | ||||||||||||||||||||||||||||
| 79 | or die "Cannot load transport class $SOAP_WSDL_TRANSPORT_OF{ $scheme } : $@"; | ||||||||||||||||||||||||||||
| 80 | 1 | return $SOAP_WSDL_TRANSPORT_OF{ $scheme }->new( %attrs ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | die "no transport class found for scheme <$scheme>"; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 24 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =pod | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 NAME | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | SOAP::WSDL::Factory::Transport - Factory for retrieving transport objects | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # from SOAP::WSDL::Client: | ||||||||||||||||||||||||||||
| 97 | $transport = SOAP::WSDL::Factory::Transport->get_transport( $url, @opt ); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # in transport class: | ||||||||||||||||||||||||||||
| 100 | package MyWickedTransport; | ||||||||||||||||||||||||||||
| 101 | use SOAP::WSDL::Factory::Transport; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # register class as transport module for httpr and https | ||||||||||||||||||||||||||||
| 104 | # (httpr is "reliable http", a protocol developed by IBM). | ||||||||||||||||||||||||||||
| 105 | SOAP::WSDL::Factory::Transport->register( 'httpr' , __PACKAGE__ ); | ||||||||||||||||||||||||||||
| 106 | SOAP::WSDL::Factory::Transport->register( 'https' , __PACKAGE__ ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | SOAP::WSDL::Transport serves as factory for retrieving transport objects for | ||||||||||||||||||||||||||||
| 111 | SOAP::WSDL. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | The actual work is done by specific transport classes. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | SOAP::WSDL::Transport tries to load one of the following classes: | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =over | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =item * the class registered for the scheme via register() | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item * the SOAP::Lite class matching the scheme | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =item * the SOAP::WSDL class matching the scheme | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =back | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 METHODS | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head2 register | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | SOAP::WSDL::Transport->register('https', 'MyWickedTransport'); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Globally registers a class for use as transport class. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head2 proxy | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | $trans->proxy('http://soap-wsdl.sourceforge.net'); | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Sets the proxy (endpoint). | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | Returns the transport for this protocol. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head2 set_transport | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Sets the current transport object. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head2 get_transport | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Gets the current transport object. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head1 WRITING YOUR OWN TRANSPORT CLASS | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 Registering a transport class | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Transport classes must be registered with SOAP::WSDL::Factory::Transport. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | This is done by executing the following code where $scheme is the URL scheme | ||||||||||||||||||||||||||||
| 158 | the class should be used for, and $module is the class' module name. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | SOAP::WSDL::Factory::Transport->register( $scheme, $module); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | To auto-register your transport class on loading, execute register() in your | ||||||||||||||||||||||||||||
| 163 | tranport class (see L<SYNOPSIS|SYNOPSIS> above). | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Multiple protocols or multiple classes are registered by multiple calls to | ||||||||||||||||||||||||||||
| 166 | register(). | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head2 Transport plugin package layout | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | You may only use transport classes whose name is either | ||||||||||||||||||||||||||||
| 171 | the module name or the module name with '::Client' appended. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head2 Methods to implement | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Transport classes must implement the interface required for SOAP::Lite | ||||||||||||||||||||||||||||
| 176 | transport classes (see L<SOAP::Lite::Transport> for details, | ||||||||||||||||||||||||||||
| 177 | L<SOAP::WSDL::Transport::HTTP|SOAP::WSDL::Transport::HTTP> for an example). | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | To provide this interface, transport modules must implement the following | ||||||||||||||||||||||||||||
| 180 | methods: | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =over | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =item * new | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item * send_receive | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Dispatches a request and returns the content of the response. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =item * code | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | Returns the status code of the last send_receive call (if any). | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =item * message | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | Returns the status message of the last send_receive call (if any). | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =item * status | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Returns the status of the last send_receive call (if any). | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =item * is_success | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Returns true after a send_receive was successful, false if it was not. | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =back | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | SOAP::Lite requires transport modules to pack client and server | ||||||||||||||||||||||||||||
| 209 | classes in one file, and to follow this naming scheme: | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Module name: | ||||||||||||||||||||||||||||
| 212 | "SOAP::Transport::" . uc($scheme) | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | Client class (additional package in module): | ||||||||||||||||||||||||||||
| 215 | "SOAP::Transport::" . uc($scheme) . "::Client" | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | Server class (additional package in module): | ||||||||||||||||||||||||||||
| 218 | "SOAP::Transport::" . uc($scheme) . "::Client" | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | SOAP::WSDL does not require you to follow these restrictions. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | There is only one restriction in SOAP::WSDL: | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | You may only use transport classes whose name is either the module name or | ||||||||||||||||||||||||||||
| 225 | the module name with '::Client' appended. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | SOAP::WSDL will try to instantiate an object of your transport class with | ||||||||||||||||||||||||||||
| 228 | '::Client' appended to allow using transport classes written for SOAP::Lite. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | This may lead to errors when a different module with the name of your | ||||||||||||||||||||||||||||
| 231 | transport module suffixed with ::Client is also loaded. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | Copyright 2004-2007 Martin Kutter. All rights reserved. | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | This file is part of SOAP-WSDL. You may distribute/modify it under | ||||||||||||||||||||||||||||
| 238 | the same terms as perl itself | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | Martin Kutter E<lt>martin.kutter fen-net.deE<gt> | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 REPOSITORY INFORMATION | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | $Rev: 851 $ | ||||||||||||||||||||||||||||
| 247 | $LastChangedBy: kutterma $ | ||||||||||||||||||||||||||||
| 248 | $Id: Transport.pm 851 2009-05-15 22:45:18Z kutterma $ | ||||||||||||||||||||||||||||
| 249 | $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Factory/Transport.pm $ | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =cut | ||||||||||||||||||||||||||||