File Coverage

lib/XML/RPC/UA/AnyEventSync.pm
Criterion Covered Total %
statement 27 46 58.7
branch 0 4 0.0
condition 0 3 0.0
subroutine 9 13 69.2
pod 3 3 100.0
total 39 69 56.5


line stmt bran cond sub pod time code
1             package XML::RPC::UA::AnyEventSync;
2              
3 1     1   1084 use strict;
  1         1  
  1         36  
4 1     1   5 use warnings;
  1         3  
  1         27  
5 1     1   5 use HTTP::Response;
  1         2  
  1         28  
6 1     1   5 use HTTP::Headers;
  1         1  
  1         23  
7 1     1   5 use AnyEvent 5.0;
  1         34  
  1         26  
8 1     1   6 use AnyEvent::HTTP 'http_request';
  1         1  
  1         42  
9 1     1   5 use Carp;
  1         2  
  1         48  
10              
11 1     1   5 use XML::RPC::Fast ();
  1         2  
  1         305  
12             our $VERSION = $XML::RPC::Fast::VERSION;
13              
14             =head1 NAME
15              
16             XML::RPC::UA::AnyEventSync - Syncronous XML::RPC useragent, using AnyEvent::HTTP
17              
18             =head1 SYNOPSIS
19              
20             use XML::RPC::Fast;
21             use XML::RPC::UA::AnyEventSync;
22            
23             my $rpc = XML::RPC::Fast->new(
24             $uri,
25             ua => XML::RPC::UA::AnyEventSync->new(
26             ua => 'YourApp/0.1',
27             timeout => 3,
28             ),
29             );
30              
31             =head1 DESCRIPTION
32              
33             Syncronous useragent for L. Couldn't be used in any AnyEvent application since using condvar->recv in every call.
34              
35             =head1 IMPLEMENTED METHODS
36              
37             =head2 new
38              
39             =head2 async = 0
40              
41             =head2 call
42              
43             =head1 SEE ALSO
44              
45             =over 4
46              
47             =item * L
48              
49             Base class (also contains documentation)
50              
51             =item * L
52              
53             Asyncronous UA using AnyEvent
54              
55             =item * L
56              
57             DBI of event-loop programming
58              
59             =item * L
60              
61             HTTP-client using AnyEvent
62              
63             =back
64              
65             =cut
66              
67              
68 0     0 1   sub async { 0 }
69              
70             sub new {
71 0     0 1   my $pkg = shift;
72 0           my %args = @_;
73 0   0       return bless \(do {my $o = $args{ua} || 'XML-RPC-Fast/'.$XML::RPC::Fast::VERSION }),$pkg;
  0            
74             }
75              
76             sub call {
77 0     0 1   my $self = shift;
78 0           my ($method, $url) = splice @_,0,2;
79 0           my %args = @_;
80 0 0         $args{cb} or croak "cb required for useragent @{[%args]}";
  0            
81 0           my $cv = AnyEvent->condvar;
82             #warn "call";
83             http_request
84             $method => $url,
85             headers => {
86             'Content-Type' => 'text/xml',
87             'User-Agent' => $$self,
88 1 0   1   6 do { use bytes; ( 'Content-Length' => length($args{body}) ) },
  1         2  
  1         6  
  0            
  0            
89             %{$args{headers} || {}},
90             },
91             body => $args{body},
92             cb => sub {
93 0           $args{cb}( HTTP::Response->new(
94             $_[1]{Status},
95             $_[1]{Reason},
96 0     0     HTTP::Headers->new(%{$_[1]}),
97             $_[0],
98             ) );
99 0           $cv->send;
100             },
101 0           ;
102 0           $cv->recv;
103 0           return;
104             }
105              
106             1;