line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::LWP::Request; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
105215
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
104
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
2066
|
use Moo; |
|
1
|
|
|
|
|
31589
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
4337
|
use HTTP::Status qw( :constants ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
575
|
|
10
|
1
|
|
|
1
|
|
6
|
use HTTP::Response; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
405
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has old_lwp_request => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
init_arg => undef, |
15
|
|
|
|
|
|
|
default => sub { |
16
|
|
|
|
|
|
|
return \&LWP::UserAgent::request; |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has default_response => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => sub { |
23
|
|
|
|
|
|
|
die "default_response must be a HTTP::Response object" |
24
|
|
|
|
|
|
|
unless (ref $_[0] && ref $_[0] eq 'HTTP::Response'); |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
default => sub { |
27
|
|
|
|
|
|
|
return HTTP::Response->new( HTTP_PRECONDITION_FAILED ); |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has missing_response_action => ( |
32
|
|
|
|
|
|
|
is => 'rw', |
33
|
|
|
|
|
|
|
isa => sub { |
34
|
|
|
|
|
|
|
die "missing_response_action must be either die or default" |
35
|
|
|
|
|
|
|
unless $_[0] eq 'die' || $_[0] eq 'default'; |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
default => sub { |
38
|
|
|
|
|
|
|
return 'die'; |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has response_list => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
isa => sub { |
45
|
|
|
|
|
|
|
die "$_[0] is not an ARRAY ref" |
46
|
|
|
|
|
|
|
unless ( ref $_[0] && ref $_[0] eq 'ARRAY' ); |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
default => sub { return []; }, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has enabled => ( |
52
|
|
|
|
|
|
|
is => 'rwp', |
53
|
|
|
|
|
|
|
init_arg => undef, |
54
|
|
|
|
|
|
|
default => sub { return 0; }, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has debug => ( |
58
|
|
|
|
|
|
|
is => 'rw', |
59
|
|
|
|
|
|
|
default => sub { return 0; }, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub enable { |
63
|
1
|
|
|
1
|
1
|
323285
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
12
|
return if $self->enabled; |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
1
|
|
90
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
167
|
|
68
|
|
|
|
|
|
|
*LWP::UserAgent::request = sub { |
69
|
6
|
|
|
6
|
|
8480
|
my $class = shift; |
70
|
|
|
|
|
|
|
|
71
|
6
|
50
|
|
|
|
50
|
warn "IN REDEFINED LWP::UserAgent::request" if $self->debug; |
72
|
|
|
|
|
|
|
|
73
|
6
|
|
|
|
|
8
|
my $response = shift @{ $self->response_list }; |
|
6
|
|
|
|
|
153
|
|
74
|
6
|
100
|
|
|
|
1131
|
return $response if defined $response; |
75
|
2
|
100
|
|
|
|
29
|
die "No response" if $self->missing_response_action eq 'die'; |
76
|
1
|
|
|
|
|
12
|
return $self->default_response; |
77
|
1
|
|
|
|
|
11
|
}; |
78
|
1
|
|
|
1
|
|
6
|
use warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
90
|
|
79
|
1
|
|
|
|
|
8
|
$self->_set_enabled(1); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub disable { |
83
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
return unless $self->enabled; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
1
|
|
6
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
88
|
0
|
|
|
|
|
0
|
*LWP::UserAgent::request = $self->old_lwp_request; |
89
|
1
|
|
|
1
|
|
6
|
use warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
183
|
|
90
|
0
|
|
|
|
|
0
|
$self->_set_enabled(0); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub add_response { |
94
|
4
|
|
|
4
|
1
|
1703
|
my ($self, $response) = @_; |
95
|
|
|
|
|
|
|
|
96
|
4
|
50
|
33
|
|
|
30
|
die "Response must be a HTTP::Response object" |
97
|
|
|
|
|
|
|
unless ref $response && ref $response eq 'HTTP::Response'; |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
7
|
push @{ $self->response_list }, $response; |
|
4
|
|
|
|
|
100
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub DEMOLISH { |
103
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->disable(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |