TaskPipe/UserAgentManager_ProxyNet.pm

filter: Statementstmt 36.1% 13 / 36 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 2 / 8 Podpod 0.0% 0 / 6 totaltotal 24.5% 15 / 61 CC 5 SCAR 17.3
CC
5
Cov
29%
after_request
12.0
inc_rno
6.0
handle_failed_request
6.0
CRAP 5.7
« TaskPipe/UserAgentManager.pm ↑ Summary TaskPipe/UserAgentManager_ProxyNet_Open.pm »
1 package TaskPipe::UserAgentManager_ProxyNet;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 with 'MooseX::ConfigCascade';
5 1 extends 'TaskPipe::UserAgentManager';
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 has max_rand => (is => 'ro', isa => 'Int', default => 4);
9 1 has cur_max => (is => 'rw', isa => 'Int', default => 0);
10 1 has cur_rno => (is => 'rw', isa => 'Int', default => 0);
11  
12  
13 sub set_max{
14 0 ▶ my $self = shift;
Subroutine set_max: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my $logger = Log::Log4perl->get_logger;
16 0 $self->cur_max( 3 + int(rand( $self->max_rand + 0.5 ) ) );
17 0 $logger->debug("Max requests on this ip set to ".$self->cur_max);
18 }
19  
20  
21 sub inc_rno{
22 0 ▶ my $self = shift;
Subroutine inc_rno: not called CC=2 SCAR=17.9
Pod undocumented
23  
24 0 my $logger = Log::Log4perl->get_logger;
25 0 $self->cur_rno( $self->cur_rno + 1 );
26 0 ▶ if ( $self->cur_rno >= $self->cur_max ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cur_rno >= $self->cur_max) { } 0 0 0
27 0 $logger->debug("Changing ip");
28 0 $self->change_ip;
29 } else {
30 0 $logger->debug("Not changing IP");
31 }
32 }
33  
34  
35 sub handle_failed_request{
36 0 ▶ my ($self,$resp) = @_;
Subroutine handle_failed_request: not called CC=2 SCAR=17.9
Pod undocumented
37 0 my $logger = Log::Log4perl->get_logger;
38  
39 0 ▶ if ( ! $resp ){
Branch: 1 branch
BranchTrueFalseTotal
if (not $resp) { } 0 0 0
40 0 $logger->warn("REQUEST FAILED - got no response");
41 } else {
42 0 $logger->warn("REQUEST FAILED - got ".$resp->status_line." content was ".$resp->decoded_content." - retrying");
43 }
44  
45 #$self->refresh;
46 0 $self->change_ip;
47 }
48  
49  
50 sub before_request{
51 0 ▶ my ($self,@params) = @_;
Subroutine before_request: not called CC=1 SCAR=6.9
Pod undocumented
52  
53 0 $self->inc_rno;
54 }
55  
56  
57  
58 sub after_request{
59 0 ▶ my ($self,$resp) = @_;
Subroutine after_request: not called CC=3 SCAR=24.8
Pod undocumented
60  
61 0 ▶ $self->handle_failed_request($resp) unless $resp && $resp->status_line =~ /^200/;
Branch: 1 branch
BranchTrueFalseTotal
unless $resp and $resp->status_line =~ /^200/ 0 0 0
Condition0%0/3
$resp and $resp->status_line =~ /^200/
!ll&&!rl&&r
000
MC/DC0%0/2
$resp and $resp->status_line =~ /^200/
$resp $resp->status_line =~ /^200/
Truth table0%0/3
A and B
A= $respB= $resp->status_line =~ /^200/
ABresult
0X0
100
111
62 }
63  
64 sub refresh{
65 0 ▶ my $self = shift;
Subroutine refresh: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 # $self->ua_handler->ua( $self->ua_handler->build_ua );
68 0 $self->change_ip;
69 }
70  
71  
72 =head1 NAME
73  
74 TaskPipe::UserAgentManager_ProxyNet - base class for proxying useragents
75  
76 =head1 DESCRIPTION
77  
78 "Proxynet" useragents are ones that can change IP. If you are creating a useragent that can do this, it is suggested that you inherit from this class. A suggested basic format for your useragent package is as follows:
79  
80 package TaskPipe::UserAgentManager_ProxyNet_MyProxySystem;
81  
82 use Moose;
83 extends 'TaskPipe::UserAgentManager_ProxyNet';
84  
85 sub init {
86 my ($self) = @_;
87  
88 # do any initialisation
89 }
90  
91 sub change_ip{
92 my ($self) = @_;
93  
94 # do what is needed
95 # to change the proxy ip
96 }
97  
98 sub before_request{
99 my ($self,$method,@param) = @_;
100  
101 # do something before each request?
102 }
103  
104 sub after_request{
105 my ($self,$resp,$method,@params) = @_;
106  
107 # do something after each request?
108 }
109  
110 __PACKAGE__->meta->make_immutable;
111 1;
112  
113 =head1 AUTHOR
114  
115 Tom Gracey <tomgracey@gmail.com>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 Copyright (c) Tom Gracey 2018
120  
121 TaskPipe is free software, licensed under
122  
123 The GNU Public License Version 3
124  
125 =cut
126  
127 1 __PACKAGE__->meta->make_immutable;
128  
129 1 1;
« TaskPipe/UserAgentManager.pm ↑ Summary TaskPipe/UserAgentManager_ProxyNet_Open.pm »