line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::WWW::Stub::Intercepter; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
70
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
60
|
|
5
|
3
|
|
|
3
|
|
13
|
use List::MoreUtils (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
44
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
945
|
use Test::WWW::Stub::Handler; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
788
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
3
|
|
|
3
|
0
|
9
|
my ($class) = @_; |
11
|
3
|
|
|
|
|
13
|
return bless { registry => {} }, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub intercept { |
15
|
26
|
|
|
26
|
0
|
79
|
my ($self, $uri, $env, $req) = @_; |
16
|
26
|
|
|
|
|
41
|
for my $pattern (sort { length $a <=> length $b } keys %{ $self->{registry} }) { |
|
114
|
|
|
|
|
189
|
|
|
26
|
|
|
|
|
125
|
|
17
|
56
|
|
|
|
|
83
|
for my $handler (@{$self->{registry}->{$pattern}}) { |
|
56
|
|
|
|
|
124
|
|
18
|
29
|
|
|
|
|
90
|
my $maybe_res = $handler->try_call($uri, $env, $req); |
19
|
29
|
100
|
|
|
|
578
|
return $maybe_res if $maybe_res; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
5
|
|
|
|
|
17
|
return undef; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub register { |
26
|
14
|
|
|
14
|
0
|
35
|
my ($self, $uri_or_re, $app_or_res) = @_; |
27
|
14
|
|
|
|
|
74
|
my $handler = Test::WWW::Stub::Handler->factory($uri_or_re, $app_or_res); |
28
|
14
|
|
100
|
|
|
87
|
$self->{registry}->{$uri_or_re} //= []; |
29
|
14
|
|
|
|
|
25
|
unshift @{$self->{registry}->{$uri_or_re}}, $handler; |
|
14
|
|
|
|
|
39
|
|
30
|
14
|
|
|
|
|
36
|
return $handler; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub unregister { |
34
|
13
|
|
|
13
|
0
|
39
|
my ($self, $uri_or_re, $handler) = @_; |
35
|
13
|
50
|
|
|
|
48
|
return unless exists $self->{registry}->{$uri_or_re}; |
36
|
|
|
|
|
|
|
|
37
|
13
|
|
|
14
|
|
58
|
my $idx = List::MoreUtils::firstidx { $_ eq $handler } @{$self->{registry}->{$uri_or_re}}; |
|
14
|
|
|
|
|
57
|
|
|
13
|
|
|
|
|
92
|
|
38
|
13
|
|
|
|
|
41
|
splice @{$self->{registry}->{$uri_or_re}}, $idx, 1; |
|
13
|
|
|
|
|
117
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |