File Coverage

lib/XML/Compile/Transport.pm
Criterion Covered Total %
statement 65 82 79.2
branch 10 24 41.6
condition 5 13 38.4
subroutine 14 18 77.7
pod 5 8 62.5
total 99 145 68.2


line stmt bran cond sub pod time code
1             # Copyrights 2007-2019 by [Mark Overmeer ].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.02.
5             # This code is part of distribution XML-Compile-SOAP. Meta-POD processed
6             # with OODoc into POD and HTML manual-pages. See README.md
7             # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8              
9             package XML::Compile::Transport;
10 3     3   2205 use vars '$VERSION';
  3         8  
  3         160  
11             $VERSION = '3.26';
12              
13 3     3   19 use base 'XML::Compile::SOAP::Extension';
  3         6  
  3         369  
14              
15 3     3   24 use warnings;
  3         5  
  3         100  
16 3     3   16 use strict;
  3         9  
  3         89  
17              
18 3     3   16 use Log::Report 'xml-compile-soap';
  3         4  
  3         29  
19              
20 3     3   891 use Log::Report::Exception ();
  3         6  
  3         51  
21              
22 3     3   52 use XML::LibXML ();
  3         12  
  3         83  
23 3     3   18 use Time::HiRes qw/time/;
  3         7  
  3         21  
24              
25              
26             sub init($)
27 2     2 0 6 { my ($self, $args) = @_;
28 2         13 $self->SUPER::init($args);
29 2   50     19 $self->{charset} = $args->{charset} || 'UTF-8';
30              
31 2   50     12 my $addr = $args->{address} || 'http://localhost';
32 2 50       10 my @addrs = ref $addr eq 'ARRAY' ? @$addr : $addr;
33              
34 2         5 $self->{addrs} = \@addrs;
35 2         5 $self;
36             }
37              
38             #-------------------------------------
39              
40              
41 3     3 1 12 sub charset() {shift->{charset}}
42              
43              
44 0     0 1 0 sub addresses() { @{shift->{addrs}} }
  0         0  
45              
46              
47             sub address()
48 2     2 1 5 { my $addrs = shift->{addrs};
49 2 50       10 @$addrs==1 ? $addrs->[0] : $addrs->[rand @$addrs];
50             }
51              
52             #-------------------------------------
53              
54              
55             sub compileClient(@)
56 2     2 1 399 { my ($self, %args) = @_;
57 2         11 my $call = $self->_prepare_call(\%args);
58 2   50     20 my $kind = $args{kind} || 'request-response';
59 2   50     14 my $format = $args{xml_format} || 0;
60              
61             sub
62 2     2   514 { my ($xmlout, $trace, $mtom) = @_;
63 2         9 my $start = time;
64 2 50       13 my $textout = ref $xmlout ? $xmlout->toString($format) : $xmlout;
65             #warn $xmlout->toString(1); # show message sent
66              
67 2         144 my $stringify = time;
68 2         8 $trace->{stringify_elapse} = $stringify - $start;
69 2         5 $trace->{transport_start} = $start;
70              
71 2         18 my ($textin, $xops) = try { $call->(\$textout, $trace, $mtom) };
  2         757  
72 2         52 my $connected = time;
73 2         8 $trace->{connect_elapse} = $connected - $stringify;
74 2 50       11 if($@)
75 0         0 { $trace->{errors} = [$@->wasFatal];
76 0         0 return;
77             }
78              
79 2         20 my $xmlin;
80 2 50       6 if($textin)
81 2         11 { $xmlin = try {XML::LibXML->load_xml(string => $$textin)};
  2         722  
82 2 50       748 if($@) { $trace->{errors} = [$@->wasFatal] }
  0         0  
83 2         21 else { $trace->{response_dom} = $xmlin }
84             }
85              
86 2         6 my $answer = $xmlin;
87 2 50       11 if($kind eq 'one-way')
    50          
88 0         0 { my $response = $trace->{http_response};
89 0 0       0 my $code = defined $response ? $response->code : -1;
90 0 0 0     0 if($code==202) { $answer ||= {} }
  0         0  
91             else
92 0         0 { push @{$trace->{errors}}, Log::Report::Exception->new
  0         0  
93             (reason => 'error', message => __"call failed with code $code")
94             }
95             }
96             elsif(!$xmlin)
97 0         0 { push @{$trace->{errors}}, Log::Report::Exception->new
  0         0  
98             (reason => 'error', message => __"no xml as answer");
99             }
100              
101 2         16 my $end = $trace->{transport_end} = time;
102              
103 2         6 $trace->{parse_elapse} = $end - $connected;
104 2         5 $trace->{transport_elapse} = $end - $start;
105              
106 2 50 33     8 wantarray || ! keys %$xops
107             or warning "loosing received XOPs";
108              
109 2 50       13 wantarray ? ($answer, $xops) : $answer;
110             }
111 2         27 }
112              
113 0     0   0 sub _prepare_call($) { panic "not implemented" }
114              
115             #--------------------------------------
116              
117              
118             { my %registered;
119 3     3 1 14 sub register($) { my ($class, $uri) = @_; $registered{$uri} = $class }
  3         12  
120 0     0 0   sub plugin($) { my ($class, $uri) = @_; $registered{$uri} }
  0            
121 0     0 0   sub registered($) { values %registered }
122             }
123              
124             #--------------------------------------
125              
126              
127             1;