Skip to content

Commit

Permalink
reverted deprecation for Mojocasts
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 16, 2012
1 parent ff3d6a9 commit 7da957a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,7 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.82 2012-04-16
- Deprecated relaxed placeholders "/(.foo)" in favor of "/#foo".
- Deprecated Mojolicious::Routes::Route->waypoint.
- Deprecated Mojolicious::Routes::Route->block.
- Improved Mojolicious::Routes::Pattern to render formats.
Expand Down
26 changes: 13 additions & 13 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -110,21 +110,9 @@ the surrounding text.
/sebastian23hello -> /(:name)hello -> {name => 'sebastian23'}
/sebastian 23hello -> /(:name)hello -> {name => 'sebastian 23'}

=head2 Relaxed placeholders

Relaxed placeholders are just like generic placeholders, but match all
characters except C</>.

/hello -> /#name/hello -> undef
/sebastian/23/hello -> /#name/hello -> undef
/sebastian.23/hello -> /#name/hello -> {name => 'sebastian.23'}
/sebastian/hello -> /#name/hello -> {name => 'sebastian'}
/sebastian23/hello -> /#name/hello -> {name => 'sebastian23'}
/sebastian 23/hello -> /#name/hello -> {name => 'sebastian 23'}

=head2 Wildcard placeholders

Wildcard placeholders are just like the two placeholders above, but match
Wildcard placeholders are just like generic placeholders, but match
absolutely everything, including C</> and C<.>.

/hello -> /*name/hello -> undef
Expand All @@ -134,6 +122,18 @@ absolutely everything, including C</> and C<.>.
/sebastian23/hello -> /*name/hello -> {name => 'sebastian23'}
/sebastian 23/hello -> /*name/hello -> {name => 'sebastian 23'}

=head2 Relaxed placeholders

Relaxed placeholders are similar to the two placeholders above, but always
require parentheses and match all characters except C</>.

/hello -> /(.name)/hello -> undef
/sebastian/23/hello -> /(.name)/hello -> undef
/sebastian.23/hello -> /(.name)/hello -> {name => 'sebastian.23'}
/sebastian/hello -> /(.name)/hello -> {name => 'sebastian'}
/sebastian23/hello -> /(.name)/hello -> {name => 'sebastian23'}
/sebastian 23/hello -> /(.name)/hello -> {name => 'sebastian 23'}

=head1 BASICS

Most commonly used features every L<Mojolicious> developer should know about.
Expand Down
21 changes: 10 additions & 11 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -5,7 +5,7 @@ has [qw/defaults reqs/] => sub { {} };
has [qw/format pattern regex/];
has quote_end => ')';
has quote_start => '(';
has relaxed_start => '#';
has relaxed_start => '.';
has symbol_start => ':';
has [qw/symbols tree/] => sub { [] };
has wildcard_start => '*';
Expand Down Expand Up @@ -203,12 +203,6 @@ sub _tokenize {
# Inside a placeholder
my $placeholder = $state ~~ [qw/relaxed symbol wildcard/];

# DEPRECATED in Leaf Fluttering In Wind!
if ($quoted && $char eq '.' && $state eq 'symbol') {
warn "Relaxed placeholders /(.foo) are DEPRECATED in favor of /#foo!\n";
$char = $relaxed;
}

# Quote start
if ($char eq $quote_start) {
$quoted = 1;
Expand All @@ -222,10 +216,15 @@ sub _tokenize {
$state = 'symbol';
}

# Relaxed or wildcard start (upgrade when quoted)
elsif ($char ~~ [$relaxed, $wildcard]) {
# Relaxed start (needs to be quoted)
elsif ($quoted && $char eq $relaxed && $state eq 'symbol') {
$tree[-1]->[0] = $state = 'relaxed';
}

# Wildcard start (upgrade when quoted)
elsif ($char eq $wildcard) {
push @tree, ['symbol', ''] unless $quoted;
$tree[-1]->[0] = $state = $char eq $relaxed ? 'relaxed' : 'wildcard';
$tree[-1]->[0] = $state = 'wildcard';
}

# Quote end
Expand Down Expand Up @@ -331,7 +330,7 @@ Pattern in compiled regex form.
my $relaxed = $pattern->relaxed_start;
$pattern = $pattern->relaxed_start('*');
Character indicating a relaxed placeholder, defaults to C<#>.
Character indicating a relaxed placeholder, defaults to C<.>.
=head2 C<reqs>
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -248,7 +248,7 @@ get '/source' => sub {
};

# GET /foo_relaxed/*
get '/foo_relaxed/#test' => sub {
get '/foo_relaxed/(.test)' => sub {
my $self = shift;
$self->render_text(
$self->stash('test') . ($self->req->headers->dnt ? 1 : 0));
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/pattern.t
Expand Up @@ -58,13 +58,13 @@ $result = $pattern->match('/test/lala');
is $result, undef, 'no result';

# Relaxed
$pattern = Mojolicious::Routes::Pattern->new('/test/#controller/:action');
$pattern = Mojolicious::Routes::Pattern->new('/test/(.controller)/:action');
$result = $pattern->match('/test/foo.bar/baz');
is $result->{controller}, 'foo.bar', 'right value';
is $result->{action}, 'baz', 'right value';
is $pattern->render({controller => 'foo.bar', action => 'baz'}),
'/test/foo.bar/baz', 'right result';
$pattern = Mojolicious::Routes::Pattern->new('/test/(#groovy)');
$pattern = Mojolicious::Routes::Pattern->new('/test/(.groovy)');
$result = $pattern->match('/test/foo.bar');
is $pattern->defaults->{format}, undef, 'no value';
is $result->{groovy}, 'foo.bar', 'right value';
Expand Down

0 comments on commit 7da957a

Please sign in to comment.