blib/lib/W3C/SOAP/Client.pm

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