File Coverage

blib/lib/APP/REST/ParallelMyUA.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package APP::REST::ParallelMyUA;
2              
3 1     1   30 use 5.006;
  1         4  
  1         39  
4 1     1   6 use strict;
  1         2  
  1         35  
5 1     1   5 use warnings FATAL => 'all';
  1         2  
  1         39  
6 1     1   4 use Data::Dumper;
  1         1  
  1         74  
7 1     1   10 use Time::HiRes qw( time sleep );
  1         2  
  1         10  
8 1     1   195 use Exporter();
  1         2  
  1         26  
9 1     1   444 use LWP::Parallel::UserAgent qw(:CALLBACK);
  0            
  0            
10              
11             use base qw(LWP::Parallel::UserAgent Exporter);
12             our @EXPORT = @LWP::Parallel::UserAgent::EXPORT_OK;
13              
14             $| = 1; #make the pipe hot
15             $Data::Dumper::Indent = 1;
16              
17             =head1 NAME
18              
19             APP::REST::ParallelMyUA -
20             provide a subclassed UserAgent to override on_connect, on_failure and
21             on_return methods
22              
23             =head1 VERSION
24              
25             Version 0.01
26              
27             =cut
28              
29             our $VERSION = '0.01';
30              
31             =head1 SYNOPSIS
32              
33             Quick summary of what the module does.
34              
35             Perhaps a little code snippet.
36              
37             use APP::REST::ParallelMyUA;
38              
39             my $pua = APP::REST::ParallelMyUA->new();
40              
41              
42             =head1 SUBROUTINES/METHODS
43              
44             =head2 new
45              
46             Object Constructor
47              
48             =cut
49              
50             sub new {
51             my ( $proto, %args ) = @_;
52             my $class = ref($proto) || $proto;
53             my $self;
54              
55             $self = bless $proto->SUPER::new(%args), $class;
56             return $self;
57             }
58              
59             =head2 on_connect
60              
61             redefine methods: on_connect gets called whenever we're about to
62             make a a connection
63              
64             =cut
65              
66             sub on_connect {
67             my ( $self, $request, $response, $entry ) = @_;
68              
69             #print time,"Connecting to ", $request->url, "\n";
70             print STDERR ".";
71             $entry->{tick}->{start} = time;
72             }
73              
74             =head2 on_failure
75              
76             on_failure gets called whenever a connection fails right away
77             (either we timed out, or failed to connect to this address before,
78             or it's a duplicate). Please note that non-connection based
79             errors, for example requests for non-existant pages, will NOT call
80             on_failure since the response from the server will be a well
81             formed HTTP response!
82              
83             =cut
84              
85             sub on_failure {
86             my ( $self, $request, $response, $entry ) = @_;
87             print "Failed to connect to ", $request->url, "\n\t", $response->code, ", ",
88             $response->message, "\n"
89             if $response;
90             }
91              
92             =head2 on_return
93              
94             on_return gets called whenever a connection (or its callback)
95             returns EOF (or any other terminating status code available for
96             callback functions). Please note that on_return gets called for
97             any successfully terminated HTTP connection! This does not imply
98             that the response sent from the server is a success!
99              
100             =cut
101              
102             sub on_return {
103             my ( $self, $request, $response, $entry ) = @_;
104             print ".";
105              
106             #print time,"Response got from ", $request->url, "\n";
107              
108             $entry->{tick}->{end} = time;
109              
110             if ( $response->is_success ) {
111              
112             #print "\n\nWoa! Request to ",$request->url," returned code ", $response->code,
113             # ": ", $response->message, "\n";
114             #print $response->content;
115             } else {
116              
117             #print "\n\nBummer! Request to ",$request->url," returned code ", $response->code,
118             # ": ", $response->message, "\n";
119             #print $response->error_as_HTML;
120             }
121             return;
122             }
123              
124             1;
125              
126             =head1 AUTHOR
127              
128             Mithun Radhakrishnan, C<< >>
129              
130             =head1 BUGS
131              
132             =head1 SUPPORT
133              
134             You can find documentation for this module with the perldoc command.
135              
136             perldoc APP::REST::ParallelMyUA
137              
138              
139             =head1 ACKNOWLEDGEMENTS
140              
141              
142             =head1 LICENSE AND COPYRIGHT
143              
144             Copyright 2014 Mithun Radhakrishnan.
145              
146             This program is free software; you can redistribute it and/or modify it
147             under the terms of the the Artistic License (2.0). You may obtain a
148             copy of the full license at:
149              
150             L
151              
152             Any use, modification, and distribution of the Standard or Modified
153             Versions is governed by this Artistic License. By using, modifying or
154             distributing the Package, you accept this license. Do not use, modify,
155             or distribute the Package, if you do not accept this license.
156              
157             If your Modified Version has been derived from a Modified Version made
158             by someone other than you, you are nevertheless required to ensure that
159             your Modified Version complies with the requirements of this license.
160              
161             This license does not grant you the right to use any trademark, service
162             mark, tradename, or logo of the Copyright Holder.
163              
164             This license includes the non-exclusive, worldwide, free-of-charge
165             patent license to make, have made, use, offer to sell, sell, import and
166             otherwise transfer the Package with respect to any patent claims
167             licensable by the Copyright Holder that are necessarily infringed by the
168             Package. If you institute patent litigation (including a cross-claim or
169             counterclaim) against any party alleging that the Package constitutes
170             direct or contributory patent infringement, then this Artistic License
171             to you shall terminate on the date that such litigation is filed.
172              
173             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
174             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
175             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
176             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
177             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
178             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
179             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
180             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181              
182              
183             =cut
184              
185             1; # End of APP::REST::ParallelMyUA