line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Router::Boom::Method; |
2
|
1
|
|
|
1
|
|
42359
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
61
|
use 5.008_005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
667
|
use Router::Boom; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
858
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "1.02"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
1
|
9
|
my $class = shift; |
13
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
14
|
1
|
|
|
|
|
2
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub add { |
18
|
5
|
|
|
5
|
1
|
22
|
my ($self, $method, $path, $opaque) = @_; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
|
|
9
|
delete $self->{router}; # clear cache |
21
|
|
|
|
|
|
|
|
22
|
5
|
100
|
100
|
|
|
21
|
if (defined($method) && !ref($method)) { |
23
|
3
|
|
|
|
|
12
|
$method = [$method]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
5
|
100
|
|
|
|
20
|
unless ($self->{path_seen}->{$path}++) { |
27
|
4
|
|
|
|
|
4
|
push @{$self->{path}}, $path; |
|
4
|
|
|
|
|
7
|
|
28
|
|
|
|
|
|
|
} |
29
|
5
|
|
|
|
|
6
|
push @{$self->{data}->{$path}}, [$method, $opaque]; |
|
5
|
|
|
|
|
16
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub routes { |
33
|
1
|
|
|
1
|
1
|
2812
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
my @routes; |
36
|
1
|
|
|
|
|
2
|
for my $path (@{$self->{path}}) { |
|
1
|
|
|
|
|
6
|
|
37
|
4
|
|
|
|
|
5
|
for my $route (@{$self->{data}->{$path}}) { |
|
4
|
|
|
|
|
11
|
|
38
|
5
|
|
|
|
|
9
|
my ($method, $opaque) = @$route; |
39
|
5
|
|
|
|
|
13
|
push @routes, [ $method, $path, $opaque ]; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
16
|
return @routes; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _method_match { |
46
|
11
|
|
|
11
|
|
13
|
my ($request_method, $matcher) = @_; |
47
|
11
|
100
|
|
|
|
27
|
return 1 if not defined($matcher); |
48
|
|
|
|
|
|
|
|
49
|
10
|
|
|
|
|
15
|
for my $m (@$matcher) { |
50
|
12
|
100
|
|
|
|
32
|
return 1 if $m eq $request_method; |
51
|
|
|
|
|
|
|
} |
52
|
5
|
|
|
|
|
13
|
return 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub match { |
56
|
10
|
|
|
10
|
1
|
33199
|
my ($self, $request_method, $path) = @_; |
57
|
|
|
|
|
|
|
|
58
|
10
|
|
66
|
|
|
49
|
$self->{router} ||= $self->_build_router(); |
59
|
|
|
|
|
|
|
|
60
|
10
|
100
|
|
|
|
42
|
if (my ($patterns, $captured) = $self->{router}->match($path)) { |
61
|
9
|
|
|
|
|
12
|
my @allowed_methods; |
62
|
9
|
|
|
|
|
19
|
for my $pattern (@$patterns) { |
63
|
11
|
100
|
|
|
|
27
|
if (_method_match($request_method, $pattern->[0])) { |
64
|
6
|
|
|
|
|
23
|
return ($pattern->[1], $captured, 0, []); |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
8
|
push @allowed_methods, @{$pattern->[0]}; |
|
5
|
|
|
|
|
12
|
|
67
|
|
|
|
|
|
|
} |
68
|
3
|
|
|
|
|
12
|
return (undef, undef, 1, \@allowed_methods); |
69
|
|
|
|
|
|
|
} else { |
70
|
1
|
|
|
|
|
6
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub regexp { |
75
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
76
|
0
|
|
0
|
|
|
0
|
$self->{router} ||= $self->_build_router(); |
77
|
0
|
|
|
|
|
0
|
$self->{router}->regexp; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _build_router { |
81
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
82
|
1
|
|
|
|
|
6
|
my $router = Router::Boom->new(); |
83
|
1
|
|
|
|
|
2
|
for my $path (@{$self->{path}}) { |
|
1
|
|
|
|
|
3
|
|
84
|
4
|
|
|
|
|
10
|
$router->add($path, $self->{data}->{$path}); |
85
|
|
|
|
|
|
|
} |
86
|
1
|
|
|
|
|
3
|
$router; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |