Skip to content

Commit

Permalink
no need to check for a placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 19, 2016
1 parent 9a825fd commit d3bb456
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.47 2016-02-18
6.47 2016-02-19
- Fixed datetime_field helper to use the correct type attribute value.

6.46 2016-02-13
Expand Down
20 changes: 7 additions & 13 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -73,7 +73,7 @@ sub render {
elsif ($optional) { $fragment = '' }
}

$str = "$fragment$str";
$str = $fragment . $str;
}

# Format can be optional
Expand Down Expand Up @@ -106,10 +106,7 @@ sub _compile {
# Placeholder
else {
unshift @$placeholders, $value;

# Placeholder
$fragment = $type ? $type eq 'relaxed' ? '([^/]+)' : '(.+)' : '([^/.]+)'
if $op eq 'placeholder';
$fragment = $type ? $type eq 'relaxed' ? '([^/]+)' : '(.+)' : '([^/.]+)';

# Custom regex
if (my $c = $constraints->{$value}) { $fragment = _compile_req($c) }
Expand All @@ -118,11 +115,11 @@ sub _compile {
exists $defaults->{$value} ? ($fragment .= '?') : ($optional = 0);
}

$block = "$fragment$block";
$block = $fragment . $block;
}

# Not rooted with a slash
$regex = "$block$regex" if $block;
$regex = $block . $regex if $block;

# Format
$regex .= _compile_format($constraints->{format}, $defaults->{format})
Expand Down Expand Up @@ -164,16 +161,13 @@ sub _tokenize {
for my $char (split '', $pattern) {

# Quoted
if ($char eq $quote_start) {
push @tree, ['placeholder', ''];
$spec = 1;
}
if ($char eq $quote_start) { push @tree, ['placeholder', ''] if ++$spec }
elsif ($char eq $quote_end) { $spec = 0 }

# Placeholder start
# Placeholder
elsif ($char eq $start) { push @tree, ['placeholder', ''] unless $spec++ }

# Relaxed or wildcard start (upgrade when quoted)
# Relaxed or wildcard (upgrade when quoted)
elsif ($char eq $relaxed || $char eq $wildcard) {
push @tree, ['placeholder', ''] unless $spec++;
$tree[-1][2] = $char eq $relaxed ? 'relaxed' : 'wildcard';
Expand Down

0 comments on commit d3bb456

Please sign in to comment.