line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Routes::Pattern; |
2
|
53
|
|
|
53
|
|
956
|
use Mojo::Base -base; |
|
53
|
|
|
|
|
154
|
|
|
53
|
|
|
|
|
409
|
|
3
|
|
|
|
|
|
|
|
4
|
53
|
|
|
53
|
|
401
|
use Carp qw(croak); |
|
53
|
|
|
|
|
201
|
|
|
53
|
|
|
|
|
121080
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has [qw(constraints defaults types)] => sub { {} }; |
7
|
|
|
|
|
|
|
has [qw(placeholder_start type_start)] => ':'; |
8
|
|
|
|
|
|
|
has [qw(placeholders tree)] => sub { [] }; |
9
|
|
|
|
|
|
|
has quote_end => '>'; |
10
|
|
|
|
|
|
|
has quote_start => '<'; |
11
|
|
|
|
|
|
|
has [qw(regex unparsed)]; |
12
|
|
|
|
|
|
|
has relaxed_start => '#'; |
13
|
|
|
|
|
|
|
has wildcard_start => '*'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub match { |
16
|
182
|
|
|
182
|
1
|
643
|
my ($self, $path, $detect) = @_; |
17
|
182
|
|
|
|
|
437
|
my $captures = $self->match_partial(\$path, $detect); |
18
|
182
|
100
|
100
|
|
|
1080
|
return !$path || $path eq '/' ? $captures : undef; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub match_partial { |
22
|
17853
|
|
|
17853
|
1
|
32453
|
my ($self, $pathref, $detect) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Compile on demand |
25
|
17853
|
100
|
|
|
|
39807
|
$self->_compile($detect) unless $self->{regex}; |
26
|
|
|
|
|
|
|
|
27
|
17853
|
100
|
|
|
|
35582
|
return undef unless my @captures = $$pathref =~ $self->regex; |
28
|
2671
|
|
|
|
|
8105
|
$$pathref = ${^POSTMATCH}; |
29
|
2671
|
100
|
|
|
|
7609
|
@captures = () if $#+ == 0; |
30
|
2671
|
|
|
|
|
4253
|
my $captures = {%{$self->defaults}}; |
|
2671
|
|
|
|
|
6313
|
|
31
|
2671
|
|
|
|
|
4786
|
for my $placeholder (@{$self->placeholders}, 'format') { |
|
2671
|
|
|
|
|
6065
|
|
32
|
2939
|
100
|
|
|
|
7921
|
last unless @captures; |
33
|
371
|
|
|
|
|
927
|
my $capture = shift @captures; |
34
|
371
|
100
|
|
|
|
1361
|
$captures->{$placeholder} = $capture if defined $capture; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2671
|
|
|
|
|
8306
|
return $captures; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1125
|
100
|
|
1125
|
1
|
5546
|
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse { |
43
|
1037
|
|
|
1037
|
1
|
1912
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
1037
|
100
|
100
|
|
|
3527
|
my $pattern = @_ % 2 ? (shift // '/') : '/'; |
46
|
1037
|
|
|
|
|
7000
|
$pattern =~ s!^/*|/+!/!g; |
47
|
1037
|
100
|
|
|
|
3080
|
return $self->constraints({@_}) if $pattern eq '/'; |
48
|
|
|
|
|
|
|
|
49
|
936
|
|
|
|
|
1889
|
$pattern =~ s!/$!!; |
50
|
936
|
|
|
|
|
2835
|
return $self->constraints({@_})->_tokenize($pattern); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub render { |
54
|
720
|
|
|
720
|
1
|
14391
|
my ($self, $values, $endpoint) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Placeholders can only be optional without a format |
57
|
720
|
|
|
|
|
1338
|
my $optional = !(my $format = $values->{format}); |
58
|
|
|
|
|
|
|
|
59
|
720
|
|
|
|
|
1111
|
my $str = ''; |
60
|
720
|
|
|
|
|
1026
|
for my $token (reverse @{$self->tree}) { |
|
720
|
|
|
|
|
1513
|
|
61
|
787
|
|
|
|
|
1933
|
my ($op, $value) = @$token; |
62
|
787
|
|
|
|
|
1197
|
my $part = ''; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Text |
65
|
787
|
100
|
|
|
|
1640
|
if ($op eq 'text') { ($part, $optional) = ($value, 0) } |
|
381
|
100
|
|
|
|
724
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Slash |
68
|
216
|
100
|
|
|
|
444
|
elsif ($op eq 'slash') { $part = '/' unless $optional } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Placeholder |
71
|
|
|
|
|
|
|
else { |
72
|
190
|
|
|
|
|
363
|
my $name = $value->[0]; |
73
|
190
|
|
|
|
|
445
|
my $default = $self->defaults->{$name}; |
74
|
190
|
|
100
|
|
|
585
|
$part = $values->{$name} // $default // ''; |
|
|
|
100
|
|
|
|
|
75
|
190
|
100
|
100
|
|
|
632
|
if (!defined $default || ($default ne $part)) { $optional = 0 } |
|
154
|
100
|
|
|
|
264
|
|
76
|
22
|
|
|
|
|
41
|
elsif ($optional) { $part = '' } |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
787
|
|
|
|
|
1964
|
$str = $part . $str; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Format can be optional |
83
|
720
|
100
|
100
|
|
|
4522
|
return $endpoint && $format ? "$str.$format" : $str; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _compile { |
87
|
696
|
|
|
696
|
|
1417
|
my ($self, $detect) = @_; |
88
|
|
|
|
|
|
|
|
89
|
696
|
|
|
|
|
1717
|
my $constraints = $self->constraints; |
90
|
696
|
|
|
|
|
1769
|
my $defaults = $self->defaults; |
91
|
696
|
|
|
|
|
1868
|
my $types = $self->types; |
92
|
|
|
|
|
|
|
|
93
|
696
|
|
|
|
|
1385
|
my $block = my $regex = ''; |
94
|
696
|
|
|
|
|
1098
|
my $optional = 1; |
95
|
696
|
|
|
|
|
1117
|
for my $token (reverse @{$self->tree}) { |
|
696
|
|
|
|
|
1660
|
|
96
|
781
|
|
|
|
|
3101
|
my ($op, $value, $type) = @$token; |
97
|
781
|
|
|
|
|
1236
|
my $part = ''; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Text |
100
|
781
|
100
|
|
|
|
1905
|
if ($op eq 'text') { ($part, $optional) = (quotemeta $value, 0) } |
|
556
|
100
|
|
|
|
1254
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Slash |
103
|
|
|
|
|
|
|
elsif ($op eq 'slash') { |
104
|
119
|
100
|
|
|
|
348
|
$regex = ($optional ? "(?:/$block)?" : "/$block") . $regex; |
105
|
119
|
|
|
|
|
238
|
($block, $optional) = ('', 1); |
106
|
119
|
|
|
|
|
258
|
next; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Placeholder |
110
|
|
|
|
|
|
|
else { |
111
|
106
|
100
|
100
|
|
|
274
|
if ($value->[1]) { $part = _compile_req($types->{$value->[1]} // '?!') } |
|
7
|
|
|
|
|
65
|
|
112
|
99
|
100
|
|
|
|
292
|
else { $part = $type ? $type eq 'relaxed' ? '([^/]+)' : '(.+)' : '([^/.]+)' } |
|
|
100
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Custom regex |
115
|
106
|
100
|
|
|
|
334
|
if (my $c = $constraints->{$value->[0]}) { $part = _compile_req($c) } |
|
14
|
|
|
|
|
56
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Optional placeholder |
118
|
106
|
100
|
|
|
|
326
|
exists $defaults->{$value->[0]} ? ($part .= '?') : ($optional = 0); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
662
|
|
|
|
|
1915
|
$block = $part . $block; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Not rooted with a slash |
125
|
696
|
100
|
|
|
|
1918
|
$regex = $block . $regex if $block; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Format |
128
|
696
|
100
|
|
|
|
3066
|
$regex .= _compile_format($constraints->{format}, exists $defaults->{format}) if $detect; |
129
|
|
|
|
|
|
|
|
130
|
696
|
|
|
|
|
12489
|
$self->regex(qr/^$regex/ps); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _compile_format { |
134
|
551
|
|
|
551
|
|
1608
|
my ($format, $has_default) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# No regex |
137
|
551
|
100
|
|
|
|
1624
|
return '' unless $format; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Default regex |
140
|
45
|
100
|
|
|
|
168
|
return '/?(?:\.([^/]+))?$' if $format eq '1'; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Compile custom regex |
143
|
41
|
|
|
|
|
124
|
my $regex = '\.' . _compile_req($format); |
144
|
41
|
100
|
|
|
|
180
|
return $has_default ? "/?(?:$regex)?\$" : "/?$regex\$"; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _compile_req { |
148
|
62
|
|
|
62
|
|
131
|
my $req = shift; |
149
|
62
|
100
|
|
|
|
227
|
return "($req)" if ref $req ne 'ARRAY'; |
150
|
47
|
|
|
|
|
202
|
return '(' . join('|', map {quotemeta} reverse sort @$req) . ')'; |
|
75
|
|
|
|
|
325
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _tokenize { |
154
|
936
|
|
|
936
|
|
2237
|
my ($self, $pattern) = @_; |
155
|
|
|
|
|
|
|
|
156
|
936
|
|
|
|
|
2045
|
my $placeholders = $self->placeholders; |
157
|
936
|
|
|
|
|
2323
|
my $type_start = $self->type_start; |
158
|
936
|
|
|
|
|
2284
|
my $quote_end = $self->quote_end; |
159
|
936
|
|
|
|
|
2154
|
my $quote_start = $self->quote_start; |
160
|
936
|
|
|
|
|
2254
|
my $start = $self->placeholder_start; |
161
|
936
|
|
|
|
|
2373
|
my $relaxed = $self->relaxed_start; |
162
|
936
|
|
|
|
|
2324
|
my $wildcard = $self->wildcard_start; |
163
|
|
|
|
|
|
|
|
164
|
936
|
|
|
|
|
1864
|
my (@tree, $spec, $more); |
165
|
936
|
|
|
|
|
5097
|
for my $char (split //, $pattern) { |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Quoted |
168
|
10309
|
50
|
100
|
|
|
64861
|
if ($char eq $quote_start) { push @tree, ['placeholder', ''] if ++$spec } |
|
30
|
100
|
100
|
|
|
105
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
169
|
30
|
|
|
|
|
72
|
elsif ($char eq $quote_end) { $spec = $more = 0 } |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Placeholder |
172
|
83
|
100
|
|
|
|
348
|
elsif (!$more && $char eq $start) { push @tree, ['placeholder', ''] unless $spec++ } |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# Relaxed or wildcard (upgrade when quoted) |
175
|
|
|
|
|
|
|
elsif (!$more && ($char eq $relaxed || $char eq $wildcard)) { |
176
|
46
|
100
|
|
|
|
189
|
push @tree, ['placeholder', ''] unless $spec++; |
177
|
46
|
100
|
|
|
|
155
|
$tree[-1][2] = $char eq $relaxed ? 'relaxed' : 'wildcard'; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Slash |
181
|
|
|
|
|
|
|
elsif ($char eq '/') { |
182
|
1326
|
|
|
|
|
3396
|
push @tree, ['slash']; |
183
|
1326
|
|
|
|
|
2595
|
$spec = $more = 0; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Placeholder |
187
|
786
|
|
|
|
|
1414
|
elsif ($spec && ++$more) { $tree[-1][1] .= $char } |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Text (optimize slash+text and *+text+slash+text) |
190
|
6819
|
|
|
|
|
11074
|
elsif ($tree[-1][0] eq 'text') { $tree[-1][-1] .= $char } |
191
|
878
|
|
|
|
|
3541
|
elsif (!$tree[-2] && $tree[-1][0] eq 'slash') { @tree = (['text', "/$char"]) } |
192
|
281
|
50
|
|
|
|
929
|
elsif ($tree[-2] && $tree[-2][0] eq 'text' && $tree[-1][0] eq 'slash') { pop @tree && ($tree[-1][-1] .= "/$char") } |
193
|
30
|
|
|
|
|
140
|
else { push @tree, ['text', $char] } |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# Placeholder types |
197
|
936
|
|
|
|
|
2588
|
for my $token (reverse @tree) { |
198
|
1222
|
100
|
|
|
|
2864
|
next unless $token->[0] eq 'placeholder'; |
199
|
147
|
100
|
|
|
|
1237
|
$token->[1] = $token->[1] =~ /^(.+)\Q$type_start\E(.+)$/ ? [$1, $2] : [$token->[1]]; |
200
|
147
|
|
|
|
|
506
|
unshift @$placeholders, $token->[1][0]; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
936
|
|
|
|
|
2846
|
return $self->unparsed($pattern)->tree(\@tree); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=encoding utf8 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 NAME |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Mojolicious::Routes::Pattern - Route pattern |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 SYNOPSIS |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
use Mojolicious::Routes::Pattern; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Create pattern |
219
|
|
|
|
|
|
|
my $pattern = Mojolicious::Routes::Pattern->new('/test/:name'); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Match routes |
222
|
|
|
|
|
|
|
my $captures = $pattern->match('/test/sebastian'); |
223
|
|
|
|
|
|
|
say $captures->{name}; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 DESCRIPTION |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L is the core of L. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L implements the following attributes. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 constraints |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
my $constraints = $pattern->constraints; |
236
|
|
|
|
|
|
|
$pattern = $pattern->constraints({foo => qr/\w+/}); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Regular expression constraints. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 defaults |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
my $defaults = $pattern->defaults; |
243
|
|
|
|
|
|
|
$pattern = $pattern->defaults({foo => 'bar'}); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Default parameters. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 placeholder_start |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
my $start = $pattern->placeholder_start; |
250
|
|
|
|
|
|
|
$pattern = $pattern->placeholder_start(':'); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Character indicating a placeholder, defaults to C<:>. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 placeholders |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
my $placeholders = $pattern->placeholders; |
257
|
|
|
|
|
|
|
$pattern = $pattern->placeholders(['foo', 'bar']); |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Placeholder names. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 quote_end |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
my $end = $pattern->quote_end; |
264
|
|
|
|
|
|
|
$pattern = $pattern->quote_end('}'); |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Character indicating the end of a quoted placeholder, defaults to C>. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 quote_start |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
my $start = $pattern->quote_start; |
271
|
|
|
|
|
|
|
$pattern = $pattern->quote_start('{'); |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Character indicating the start of a quoted placeholder, defaults to C>. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 regex |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
my $regex = $pattern->regex; |
278
|
|
|
|
|
|
|
$pattern = $pattern->regex($regex); |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Pattern in compiled regular expression form. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 relaxed_start |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
my $start = $pattern->relaxed_start; |
285
|
|
|
|
|
|
|
$pattern = $pattern->relaxed_start('*'); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Character indicating a relaxed placeholder, defaults to C<#>. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head2 tree |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
my $tree = $pattern->tree; |
292
|
|
|
|
|
|
|
$pattern = $pattern->tree([['text', '/foo']]); |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Pattern in parsed form. Note that this structure should only be used very carefully since it is very dynamic. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head2 type_start |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
my $start = $pattern->type_start; |
299
|
|
|
|
|
|
|
$pattern = $pattern->type_start('|'); |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Character indicating the start of a placeholder type, defaults to C<:>. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head2 types |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
my $types = $pattern->types; |
306
|
|
|
|
|
|
|
$pattern = $pattern->types({int => qr/[0-9]+/}); |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Placeholder types. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head2 unparsed |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
my $unparsed = $pattern->unparsed; |
313
|
|
|
|
|
|
|
$pattern = $pattern->unparsed('/:foo/:bar'); |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Raw unparsed pattern. |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=head2 wildcard_start |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
my $start = $pattern->wildcard_start; |
320
|
|
|
|
|
|
|
$pattern = $pattern->wildcard_start('*'); |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Character indicating the start of a wildcard placeholder, defaults to C<*>. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head1 METHODS |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones. |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head2 match |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
my $captures = $pattern->match('/foo/bar'); |
331
|
|
|
|
|
|
|
my $captures = $pattern->match('/foo/bar', 1); |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
Match pattern against entire path, format detection is disabled by default. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head2 match_partial |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
my $captures = $pattern->match_partial(\$path); |
338
|
|
|
|
|
|
|
my $captures = $pattern->match_partial(\$path, 1); |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Match pattern against path and remove matching parts, format detection is disabled by default. |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=head2 new |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
my $pattern = Mojolicious::Routes::Pattern->new; |
345
|
|
|
|
|
|
|
my $pattern = Mojolicious::Routes::Pattern->new('/users/:id'); |
346
|
|
|
|
|
|
|
my $pattern = Mojolicious::Routes::Pattern->new('/user/:id', id => qr/\d+/); |
347
|
|
|
|
|
|
|
my $pattern = Mojolicious::Routes::Pattern->new(format => ['json', 'yaml']); |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Construct a new L object and L"parse"> pattern if necessary. |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head2 parse |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
$pattern = $pattern->parse('/user/:id'); |
354
|
|
|
|
|
|
|
$pattern = $pattern->parse('/user/:id', id=> qr/\d+/); |
355
|
|
|
|
|
|
|
$pattern = $pattern->parse(format => ['json', 'yaml']); |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
Parse pattern. |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=head2 render |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
my $path = $pattern->render({id => 24}); |
362
|
|
|
|
|
|
|
my $path = $pattern->render({id => 24}, 1); |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
Render pattern into a path with parameters, format rendering is disabled by default. |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=head1 SEE ALSO |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
L, L, L. |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=cut |