line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::LWP::Conditional::Stubs; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
47966
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
231
|
|
4
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
264
|
|
5
|
7
|
|
|
7
|
|
40
|
use Scalar::Util qw(blessed); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
2479
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
9
|
|
|
9
|
0
|
428
|
my $class = shift; |
9
|
9
|
|
|
|
|
262
|
return bless +{ count => 0, stubs => [] }, $class; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_http_res { |
13
|
36
|
|
|
36
|
0
|
58
|
my ($self, $res) = @_; |
14
|
36
|
|
66
|
|
|
501
|
return blessed($res) && $res->isa('HTTP::Response'); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub is_stub { |
18
|
13
|
|
|
13
|
0
|
30
|
my ($self, $stub) = @_; |
19
|
13
|
|
66
|
|
|
40
|
return $self->is_http_res($stub) || ref($stub) eq 'CODE'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add { |
23
|
13
|
|
|
13
|
0
|
93
|
my ($self, $stub) = @_; |
24
|
13
|
50
|
|
|
|
156
|
push @{$self->{stubs}}, $stub if $self->is_stub($stub); |
|
13
|
|
|
|
|
189
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub execute { |
28
|
23
|
|
|
23
|
0
|
46
|
my ($self, $req) = @_; |
29
|
|
|
|
|
|
|
|
30
|
23
|
|
|
|
|
56
|
my $i = $self->{count}++; |
31
|
23
|
|
50
|
|
|
132
|
my $stub = $self->{stubs}->[$i] || $self->{stubs}->[-1] || return; |
32
|
|
|
|
|
|
|
|
33
|
23
|
100
|
|
|
|
88
|
if ($self->is_http_res($stub)) { |
|
|
50
|
|
|
|
|
|
34
|
22
|
|
|
|
|
96
|
return $stub; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif (ref($stub) eq 'CODE') { |
37
|
1
|
|
|
|
|
5
|
return $stub->($req); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |