line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
#PODNAME: Raisin::Routes::Endpoint |
3
|
|
|
|
|
|
|
#ABSTRACT: Endpoint class for Raisin::Routes. |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
538
|
use strict; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
431
|
|
6
|
14
|
|
|
14
|
|
74
|
use warnings; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
843
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Raisin::Routes::Endpoint; |
9
|
|
|
|
|
|
|
$Raisin::Routes::Endpoint::VERSION = '0.93'; |
10
|
14
|
|
|
|
|
128
|
use Plack::Util::Accessor qw( |
11
|
|
|
|
|
|
|
check |
12
|
|
|
|
|
|
|
code |
13
|
|
|
|
|
|
|
desc |
14
|
|
|
|
|
|
|
entity |
15
|
|
|
|
|
|
|
method |
16
|
|
|
|
|
|
|
named |
17
|
|
|
|
|
|
|
params |
18
|
|
|
|
|
|
|
path |
19
|
|
|
|
|
|
|
regex |
20
|
|
|
|
|
|
|
summary |
21
|
|
|
|
|
|
|
produces |
22
|
14
|
|
|
14
|
|
96
|
); |
|
14
|
|
|
|
|
28
|
|
23
|
|
|
|
|
|
|
|
24
|
14
|
|
|
14
|
|
2006
|
use Raisin::Util; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
9287
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
83
|
|
|
83
|
0
|
54567
|
my ($class, %args) = @_; |
28
|
|
|
|
|
|
|
|
29
|
83
|
|
|
|
|
197
|
my $self = bless {}, $class; |
30
|
|
|
|
|
|
|
|
31
|
83
|
|
|
|
|
308
|
$self->check({}); |
32
|
83
|
|
|
|
|
699
|
$self->params([]); |
33
|
|
|
|
|
|
|
|
34
|
83
|
|
|
|
|
780
|
@$self{ keys %args } = values %args; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Populate params index |
37
|
83
|
|
|
|
|
180
|
for my $p (@{ $self->params }) { |
|
83
|
|
|
|
|
191
|
|
38
|
59
|
50
|
66
|
|
|
343
|
if ($p->named && (my $re = $p->regex)) { |
39
|
0
|
|
|
|
|
0
|
$re =~ s/[\$^]//g; |
40
|
0
|
|
|
|
|
0
|
$self->{check}{ $p->name } = $re; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
83
|
|
|
|
|
576
|
$self->regex($self->_build_regex); |
45
|
83
|
|
|
|
|
637
|
$self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_regex { |
49
|
83
|
|
|
83
|
|
136
|
my $self = shift; |
50
|
83
|
50
|
|
|
|
178
|
return $self->path if ref($self->path) eq 'Regexp'; |
51
|
|
|
|
|
|
|
|
52
|
83
|
|
|
|
|
494
|
my $regex = $self->path; |
53
|
|
|
|
|
|
|
|
54
|
83
|
|
|
|
|
758
|
$regex =~ s/(.?)([:*?])(\w+)/$self->_rep_regex($1, $2, $3)/eg; |
|
50
|
|
|
|
|
140
|
|
55
|
83
|
|
|
|
|
225
|
$regex =~ s/[{}]//g; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Allows any extensions |
58
|
83
|
|
|
|
|
162
|
$regex .= "(?:\\\.[^.]+?)?"; |
59
|
|
|
|
|
|
|
|
60
|
83
|
|
|
|
|
1872
|
qr/^$regex$/; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _rep_regex { |
64
|
50
|
|
|
50
|
|
224
|
my ($self, $char, $switch, $token) = @_; |
65
|
|
|
|
|
|
|
|
66
|
50
|
|
|
|
|
158
|
my ($a, $b, $r) = ("(?<$token>", ')', undef); |
67
|
|
|
|
|
|
|
|
68
|
50
|
|
|
|
|
110
|
for ($switch) { |
69
|
50
|
50
|
33
|
|
|
151
|
if ($_ eq ':' || $_ eq '?') { |
70
|
50
|
|
50
|
|
|
138
|
$r = $a . ($self->check->{$token} // '[^/]+?') . $b; |
71
|
|
|
|
|
|
|
} |
72
|
50
|
50
|
|
|
|
406
|
if ($_ eq '*') { |
73
|
0
|
|
|
|
|
0
|
$r = $a . '.+' . $b; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
50
|
50
|
33
|
|
|
262
|
$char = $char . '?' if $char eq '/' && $switch eq '?'; |
78
|
50
|
50
|
|
|
|
115
|
$r .= '?' if $switch eq '?'; |
79
|
|
|
|
|
|
|
|
80
|
50
|
|
|
|
|
200
|
return $char . $r; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub tags { |
84
|
20
|
|
|
20
|
0
|
236
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
20
|
100
|
|
|
|
45
|
unless ($self->{tags}) { |
87
|
17
|
|
|
|
|
35
|
return [Raisin::Util::make_tag_from_path($self->path)]; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
14
|
$self->{tags}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub match { |
94
|
463
|
|
|
463
|
0
|
20132
|
my ($self, $method, $path) = @_; |
95
|
|
|
|
|
|
|
|
96
|
463
|
|
|
|
|
726
|
$self->{named} = undef; |
97
|
|
|
|
|
|
|
|
98
|
463
|
100
|
66
|
|
|
1212
|
return if !$method || lc($method) ne lc($self->method); |
99
|
142
|
100
|
|
|
|
1319
|
return if $path !~ $self->regex; |
100
|
|
|
|
|
|
|
|
101
|
13
|
|
|
13
|
|
6737
|
my %captured = %+; |
|
13
|
|
|
|
|
5497
|
|
|
13
|
|
|
|
|
1623
|
|
|
72
|
|
|
|
|
1336
|
|
102
|
|
|
|
|
|
|
|
103
|
72
|
|
|
|
|
173
|
foreach my $p (@{ $self->params }) { |
|
72
|
|
|
|
|
214
|
|
104
|
84
|
100
|
|
|
|
449
|
next unless $p->named; |
105
|
24
|
|
|
|
|
149
|
my $copy = $captured{ $p->name }; |
106
|
24
|
100
|
|
|
|
161
|
return unless $p->validate(\$copy, 'quite'); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
71
|
|
|
|
|
423
|
$self->named(\%captured); |
110
|
|
|
|
|
|
|
|
111
|
71
|
|
|
|
|
549
|
1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |