| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Router::Simple; |
|
2
|
11
|
|
|
11
|
|
58594
|
use strict; |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
377
|
|
|
3
|
11
|
|
|
11
|
|
205
|
use warnings; |
|
|
11
|
|
|
|
|
17
|
|
|
|
11
|
|
|
|
|
278
|
|
|
4
|
11
|
|
|
11
|
|
349
|
use 5.00800; |
|
|
11
|
|
|
|
|
44
|
|
|
|
11
|
|
|
|
|
648
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
|
6
|
11
|
|
|
11
|
|
7770
|
use Router::Simple::SubMapper; |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
295
|
|
|
7
|
11
|
|
|
11
|
|
7726
|
use Router::Simple::Route; |
|
|
11
|
|
|
|
|
39
|
|
|
|
11
|
|
|
|
|
392
|
|
|
8
|
11
|
|
|
11
|
|
97
|
use List::Util qw/max/; |
|
|
11
|
|
|
|
|
31
|
|
|
|
11
|
|
|
|
|
1422
|
|
|
9
|
11
|
|
|
11
|
|
62
|
use Carp (); |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
4784
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Class::Accessor::Lite 0.05 ( |
|
12
|
11
|
|
|
|
|
100
|
ro => [qw(routes)], |
|
13
|
11
|
|
|
11
|
|
227
|
); |
|
|
11
|
|
|
|
|
937
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $_METHOD_NOT_ALLOWED; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
10
|
|
|
10
|
1
|
153
|
bless {routes => []}, shift; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub connect { |
|
22
|
36
|
|
|
36
|
1
|
213
|
my $self = shift; |
|
23
|
36
|
|
|
|
|
161
|
my $route = Router::Simple::Route->new(@_); |
|
24
|
36
|
|
|
|
|
48
|
push @{ $self->{routes} }, $route; |
|
|
36
|
|
|
|
|
115
|
|
|
25
|
36
|
|
|
|
|
91
|
return $self; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub submapper { |
|
29
|
3
|
|
|
3
|
1
|
15
|
my ($self, $pattern, $dest, $opt) = @_; |
|
30
|
3
|
|
50
|
|
|
39
|
return Router::Simple::SubMapper->new( |
|
|
|
|
50
|
|
|
|
|
|
31
|
|
|
|
|
|
|
parent => $self, |
|
32
|
|
|
|
|
|
|
pattern => $pattern, |
|
33
|
|
|
|
|
|
|
dest => $dest || +{}, |
|
34
|
|
|
|
|
|
|
opt => $opt || +{}, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _match { |
|
39
|
33
|
|
|
33
|
|
55
|
my ($self, $env) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
33
|
100
|
|
|
|
761
|
if (ref $env) { |
|
42
|
|
|
|
|
|
|
# "I think there was a discussion about that a while ago and it is up to apps to deal with empty PATH_INFO as root / iirc" |
|
43
|
|
|
|
|
|
|
# -- by @miyagawa |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
# see http://blog.64p.org/entry/2012/10/05/132354 |
|
46
|
26
|
100
|
|
|
|
84
|
if ($env->{PATH_INFO} eq '') { |
|
47
|
1
|
|
|
|
|
3
|
$env->{PATH_INFO} = '/'; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} else { |
|
50
|
7
|
|
|
|
|
25
|
$env = +{ PATH_INFO => $env } |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
33
|
|
|
|
|
51
|
local $_METHOD_NOT_ALLOWED; |
|
54
|
33
|
|
|
|
|
59
|
$self->{method_not_allowed} = 0; |
|
55
|
33
|
|
|
|
|
41
|
for my $route (@{$self->{routes}}) { |
|
|
33
|
|
|
|
|
540
|
|
|
56
|
91
|
|
|
|
|
372
|
my $match = $route->match($env); |
|
57
|
91
|
100
|
|
|
|
549
|
return ($match, $route) if $match; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
7
|
|
|
|
|
16
|
$self->{method_not_allowed} = $_METHOD_NOT_ALLOWED; |
|
60
|
7
|
|
|
|
|
18
|
return undef; # not matched. |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub method_not_allowed { |
|
64
|
5
|
|
|
5
|
1
|
2016
|
my $self = shift; |
|
65
|
5
|
|
|
|
|
21
|
$self->{method_not_allowed}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub match { |
|
69
|
32
|
|
|
32
|
1
|
11445
|
my ($self, $req) = @_; |
|
70
|
32
|
|
|
|
|
86
|
my ($match) = $self->_match($req); |
|
71
|
32
|
|
|
|
|
125
|
return $match; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub routematch { |
|
75
|
1
|
|
|
1
|
1
|
12
|
my ($self, $req) = @_; |
|
76
|
1
|
|
|
|
|
3
|
return $self->_match($req); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub as_string { |
|
80
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
my $mn = max(map { $_->{name} ? length($_->{name}) : 0 } @{$self->{routes}}); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
my $nn = max(map { $_->{method} ? length(join(",",@{$_->{method}})) : 0 } @{$self->{routes}}); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return join('', map { |
|
86
|
0
|
|
0
|
|
|
|
sprintf "%-${mn}s %-${nn}s %s\n", $_->{name}||'', join(',', @{$_->{method} || []}) || '', $_->{pattern} |
|
|
0
|
|
0
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
} @{$self->{routes}}) . "\n"; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
__END__ |