| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package W3C::SOAP::Client; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Created on: 2012-05-28 07:40:20 | 
| 4 |  |  |  |  |  |  | # Create by:  Ivan Wills | 
| 5 |  |  |  |  |  |  | # $Id$ | 
| 6 |  |  |  |  |  |  | # $Revision$, $HeadURL$, $Date$ | 
| 7 |  |  |  |  |  |  | # $Revision$, $Source$, $Date$ | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 952 | use Moose; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 10 | 1 |  |  | 1 |  | 4614 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 11 | 1 |  |  | 1 |  | 4 | use version; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 12 | 1 |  |  | 1 |  | 51 | use Carp qw/carp croak cluck confess longmess/; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 55 |  | 
| 13 | 1 |  |  | 1 |  | 4 | use Scalar::Util; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 14 | 1 |  |  | 1 |  | 4 | use List::Util; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 15 | 1 |  |  | 1 |  | 3 | use Data::Dumper qw/Dumper/; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 16 | 1 |  |  | 1 |  | 4 | use English qw/ -no_match_vars /; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 17 | 1 |  |  | 1 |  | 958 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 50970 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 18 | 1 |  |  | 1 |  | 9 | use Try::Tiny; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 63 |  | 
| 19 | 1 |  |  | 1 |  | 284 | use XML::LibXML; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | use W3C::SOAP::Exception; | 
| 21 |  |  |  |  |  |  | use W3C::SOAP::Header; | 
| 22 |  |  |  |  |  |  | use Moose::Util::TypeConstraints qw/duck_type/; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | extends 'W3C::SOAP::Base'; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | our $VERSION     = version->new('0.11'); | 
| 27 |  |  |  |  |  |  | our $DEBUG_REQUEST_RESPONSE = $ENV{W3C_SOAP_DEBUG_CLIENT}; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | has location => ( | 
| 30 |  |  |  |  |  |  | is       => 'rw', | 
| 31 |  |  |  |  |  |  | isa      => 'Str', | 
| 32 |  |  |  |  |  |  | required => 1, | 
| 33 |  |  |  |  |  |  | ); | 
| 34 |  |  |  |  |  |  | has mech => ( | 
| 35 |  |  |  |  |  |  | is        => 'rw', | 
| 36 |  |  |  |  |  |  | predicate => 'has_mech', | 
| 37 |  |  |  |  |  |  | init_arg  => 0, | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  | has ua => ( | 
| 40 |  |  |  |  |  |  | is       => 'rw', | 
| 41 |  |  |  |  |  |  | isa      => 'LWP::UserAgent', | 
| 42 |  |  |  |  |  |  | builder  => '_ua', | 
| 43 |  |  |  |  |  |  | required => 1, | 
| 44 |  |  |  |  |  |  | lazy     => 1, | 
| 45 |  |  |  |  |  |  | ); | 
| 46 |  |  |  |  |  |  | has response => ( | 
| 47 |  |  |  |  |  |  | is      => 'rw', | 
| 48 |  |  |  |  |  |  | isa     => 'HTTP::Response', | 
| 49 |  |  |  |  |  |  | clearer => 'clear_response', | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  | has log => ( | 
| 52 |  |  |  |  |  |  | is        => 'rw', | 
| 53 |  |  |  |  |  |  | isa       => duck_type([qw/ debug info warn error fatal /]), | 
| 54 |  |  |  |  |  |  | predicate => 'has_log', | 
| 55 |  |  |  |  |  |  | clearer   => 'clear_log', | 
| 56 |  |  |  |  |  |  | ); | 
| 57 |  |  |  |  |  |  | has content_type => ( | 
| 58 |  |  |  |  |  |  | is      => 'rw', | 
| 59 |  |  |  |  |  |  | isa     => 'Str', | 
| 60 |  |  |  |  |  |  | default => 'text/xml;charset=UTF-8', | 
| 61 |  |  |  |  |  |  | ); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub post { | 
| 64 |  |  |  |  |  |  | my ($self, $action, $xml) = @_; | 
| 65 |  |  |  |  |  |  | my $url = $self->location; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | cluck "The mech attribute has been deprecated and is replaced by ua attribute!" | 
| 68 |  |  |  |  |  |  | if $self->has_mech; | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | $self->clear_response; | 
| 71 |  |  |  |  |  |  | my $response = $self->ua->post( | 
| 72 |  |  |  |  |  |  | $url, | 
| 73 |  |  |  |  |  |  | 'Content-Type'     => $self->content_type, | 
| 74 |  |  |  |  |  |  | 'SOAPAction'       => qq{"$action"}, | 
| 75 |  |  |  |  |  |  | 'Proxy-Connection' => 'Keep-Alive', | 
| 76 |  |  |  |  |  |  | 'Accept-Encoding'  => 'gzip, deflate', | 
| 77 |  |  |  |  |  |  | Content            => $xml->toString, | 
| 78 |  |  |  |  |  |  | ); | 
| 79 |  |  |  |  |  |  | $self->response($response); | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | return $response->decoded_content; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | { | 
| 85 |  |  |  |  |  |  | my $ua; | 
| 86 |  |  |  |  |  |  | sub _ua { | 
| 87 |  |  |  |  |  |  | return $ua if $ua; | 
| 88 |  |  |  |  |  |  | $ua = LWP::UserAgent->new; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | if ($DEBUG_REQUEST_RESPONSE) { | 
| 91 |  |  |  |  |  |  | $ua->add_handler("request_send",  sub { shift->dump( prefix => 'REQUEST  ', maxlength => $ENV{W3C_SOAP_DEBUG_LENGTH} || 1024 ); return }); | 
| 92 |  |  |  |  |  |  | $ua->add_handler("response_done", sub { shift->dump( prefix => 'RESPONSE ', maxlength => $ENV{W3C_SOAP_DEBUG_LENGTH} || 1024 ); return }); | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | return $ua; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | 1; | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | __END__ | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 NAME | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | W3C::SOAP::Client - Client to talk SOAP to a server. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 VERSION | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | This documentation refers to W3C::SOAP::Client version 0.11. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | use W3C::SOAP::Client; | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | # post a SOAP action | 
| 116 |  |  |  |  |  |  | my $client = W3C::SOAP::Client->new( | 
| 117 |  |  |  |  |  |  | location => 'http://some.where.com/', | 
| 118 |  |  |  |  |  |  | ); | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | $client->post('DO_SOMETHING', $xms_doc); | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | L<W3C::SOAP::Client> is the base class for L<W3C::SOAP> clients. It provides | 
| 125 |  |  |  |  |  |  | the base attributes that are needed for sending SOAP requests. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =over 4 | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =item location | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | The URL for the SOAP request | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =item mech | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | No longer used | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =item ua | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | A L<LWP::UserAgent> compatible object which if not supplied will be lazily | 
| 142 |  |  |  |  |  |  | created. | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =item response | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | The L<HTTP::Response> object of the last returned response | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =item log | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | An logging object that proves the following methods: | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | debug, info, warn, error and fatal | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =item content_type | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | The value of the Content-Type HTTP header (defaults to text/xml;charset=UTF-8') | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =back | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =over 4 | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =item C<post ($action, $xml)> | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | Performs the SOAP POST request. | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =back | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =head1 DIAGNOSTICS | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =head1 CONFIGURATION AND ENVIRONMENT | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | The environment variable C<W3C_SOAP_DEBUG_CLIENT> can be used to show | 
| 175 |  |  |  |  |  |  | request and response XML. | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head1 INCOMPATIBILITIES | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =head1 BUGS AND LIMITATIONS | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | There are no known bugs in this module. | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Please report problems to Ivan Wills (ivan.wills@gmail.com). | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | Patches are welcome. | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head1 AUTHOR | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | Ivan Wills - (ivan.wills@gmail.com) | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | 
| 196 |  |  |  |  |  |  | All rights reserved. | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | This module is free software; you can redistribute it and/or modify it under | 
| 199 |  |  |  |  |  |  | the same terms as Perl itself. See L<perlartistic>.  This program is | 
| 200 |  |  |  |  |  |  | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | 
| 201 |  |  |  |  |  |  | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | 
| 202 |  |  |  |  |  |  | PARTICULAR PURPOSE. | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | =cut |