line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::WWW::Stub::Intercepter; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
22
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
88
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
17
|
use List::MoreUtils (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
46
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1418
|
use Test::WWW::Stub::Handler; |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
1085
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
3
|
|
|
3
|
0
|
10
|
my ($class) = @_; |
11
|
3
|
|
|
|
|
20
|
return bless { registry => {} }, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub intercept { |
15
|
35
|
|
|
35
|
0
|
96
|
my ($self, $uri, $env, $req) = @_; |
16
|
35
|
|
|
|
|
66
|
for my $pattern (sort { length $a <=> length $b } keys %{ $self->{registry} }) { |
|
235
|
|
|
|
|
435
|
|
|
35
|
|
|
|
|
175
|
|
17
|
77
|
|
|
|
|
130
|
for my $handler (@{$self->{registry}->{$pattern}}) { |
|
77
|
|
|
|
|
198
|
|
18
|
37
|
|
|
|
|
149
|
my $maybe_res = $handler->try_call($uri, $env, $req); |
19
|
37
|
100
|
|
|
|
626
|
return $maybe_res if $maybe_res; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
10
|
|
|
|
|
33
|
return undef; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub register { |
26
|
14
|
|
|
14
|
0
|
43
|
my ($self, $uri_or_re, $app_or_res) = @_; |
27
|
14
|
|
|
|
|
78
|
my $handler = Test::WWW::Stub::Handler->factory($uri_or_re, $app_or_res); |
28
|
14
|
|
100
|
|
|
91
|
$self->{registry}->{$uri_or_re} //= []; |
29
|
14
|
|
|
|
|
23
|
unshift @{$self->{registry}->{$uri_or_re}}, $handler; |
|
14
|
|
|
|
|
41
|
|
30
|
14
|
|
|
|
|
36
|
return $handler; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub unregister { |
34
|
13
|
|
|
13
|
0
|
41
|
my ($self, $uri_or_re, $handler) = @_; |
35
|
13
|
50
|
|
|
|
54
|
return unless exists $self->{registry}->{$uri_or_re}; |
36
|
|
|
|
|
|
|
|
37
|
13
|
|
|
14
|
|
59
|
my $idx = List::MoreUtils::firstidx { $_ eq $handler } @{$self->{registry}->{$uri_or_re}}; |
|
14
|
|
|
|
|
58
|
|
|
13
|
|
|
|
|
85
|
|
38
|
13
|
|
|
|
|
39
|
splice @{$self->{registry}->{$uri_or_re}}, $idx, 1; |
|
13
|
|
|
|
|
148
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |