Skip to content

Commit

Permalink
allow relaxed placeholders to be customized
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 18, 2016
1 parent 386a44b commit 6984366
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -182,7 +182,7 @@ sub _tokenize {
# Relaxed or wildcard start (upgrade when quoted)
elsif ($char eq $relaxed || $char eq $wildcard) {
push @tree, ['placeholder', ''] unless $spec++;
$tree[-1][2] = $char eq '#' ? 'relaxed' : 'wildcard';
$tree[-1][2] = $char eq $relaxed ? 'relaxed' : 'wildcard';
}

# Slash
Expand Down
14 changes: 8 additions & 6 deletions t/mojolicious/routes.t
Expand Up @@ -220,9 +220,10 @@ $similar->route('/too')->via('PATCH')->to('similar#post');
$r->add_type(test => qr/test/)->route('/')->get('/custom_type/(whatever:test)');

# /custom_pattern/test_*_test
my $custom = $r->get->to('custom#pattern');
$custom->pattern->quote_start('{')->quote_end('}')->placeholder_start('.');
$custom->parse('/custom_pattern/test_{.custom}_test');
my $custom = $r->get->to(four => 4);
$custom->pattern->quote_start('{')->quote_end('}')->placeholder_start('.')
->relaxed_start('$')->wildcard_start('@');
$custom->parse('/custom_pattern/a_{.one}_b/{$two}/{@three}');

# Cached lookup
my $fast = $r->route('/fast');
Expand Down Expand Up @@ -957,10 +958,11 @@ is_deeply $m->stack, [], 'empty stack';

# Custom pattern
$m = Mojolicious::Routes::Match->new(root => $r);
$m->find($c => {method => 'GET', path => '/custom_pattern/test_123_test'});
$m->find(
$c => {method => 'GET', path => '/custom_pattern/a_123_b/c.123/d/123'});
is_deeply $m->stack,
[{controller => 'custom', action => 'pattern', 'custom' => 123}],
[{one => 123, two => 'c.123', three => 'd/123', four => 4}],
'right structure';
is $m->path_for->{path}, '/custom_pattern/test_123_test', 'right path';
is $m->path_for->{path}, '/custom_pattern/a_123_b/c.123/d/123', 'right path';

done_testing();

0 comments on commit 6984366

Please sign in to comment.