Skip to content

Commit

Permalink
deprecated class and method stash values in favor of controller and a…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
kraih committed Feb 26, 2012
1 parent 72b2d02 commit 6468750
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.54 2012-02-26 00:00:00
- Deprecated class and method stash value in favor of controller and
action.
- Added EXPERIMENTAL patch function to Mojolicious::Lite.
- Added EXPERIMENTAL patch method to Mojolicious::Routes.
- Added EXPERIMENTAL patch method to Mojo::UserAgent.
Expand Down
15 changes: 7 additions & 8 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -354,11 +354,10 @@ sub render_static {
my ($self, $file) = @_;

my $app = $self->app;
unless ($app->static->serve($self, $file)) {
$app->log->debug(
qq/Static file "$file" not found, public directory missing?/);
return;
}
$app->log->debug(
qq/Static file "$file" not found, public directory missing?/)
and return
unless $app->static->serve($self, $file);
$self->rendered;

return 1;
Expand Down Expand Up @@ -964,9 +963,9 @@ Cookies failing signature verification will be automatically discarded.
Non persistent data storage and exchange, application wide default values can
be set with L<Mojolicious/"defaults">. Many stash value have a special
meaning and are reserved, the full list is currently C<action>, C<app>,
C<cb>, C<class>, C<controller>, C<data>, C<extends>, C<format>, C<handler>,
C<json>, C<layout>, C<method>, C<namespace>, C<partial>, C<path>, C<status>,
C<template> and C<text>.
C<cb>, C<controller>, C<data>, C<extends>, C<format>, C<handler>, C<json>,
C<layout>, C<namespace>, C<partial>, C<path>, C<status>, C<template> and
C<text>.
$c->stash->{foo} = 'bar';
my $foo = $c->stash->{foo};
Expand Down
37 changes: 16 additions & 21 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -367,10 +367,8 @@ sub _dispatch_controller {
if (my $e = Mojo::Loader->load($app)) {

# Doesn't exist
unless (ref $e) {
$c->app->log->debug("$app does not exist, maybe a typo?");
return;
}
$c->app->log->debug("$app does not exist, maybe a typo?") and return
unless ref $e;

# Error
return $e;
Expand Down Expand Up @@ -442,7 +440,9 @@ sub _dispatch_controller {
sub _generate_class {
my ($self, $field, $c) = @_;

# Class
# DEPRECATED in Leaf Fluttering In Wind!
warn "The class stash value is DEPRECATED in favor of controller!\n"
if $field->{class};
my $class = camelize $field->{class} || $field->{controller} || '';

# Namespace
Expand All @@ -462,23 +462,20 @@ sub _generate_method {
my ($self, $field, $c) = @_;

# Prepare hidden
unless ($self->{hiding}) {
$self->{hiding} = {};
$self->{hiding}->{$_}++ for @{$self->hidden};
}
unless ($self->{hiding}) { $self->{hiding}->{$_}++ for @{$self->hidden} }

# Hidden
# DEPRECATED in Leaf Fluttering In Wind!
warn "The method stash value is DEPRECATED in favor of action!\n"
if $field->{method};
return unless my $method = $field->{method} || $field->{action};
if ($self->{hiding}->{$method} || index($method, '_') == 0) {
$c->app->log->debug(qq/Action "$method" is not allowed./);
return;
}

# Hidden
$c->app->log->debug(qq/Action "$method" is not allowed./) and return
if $self->{hiding}->{$method} || index($method, '_') == 0;

# Invalid
unless ($method =~ /^[a-zA-Z0-9_:]+$/) {
$c->app->log->debug(qq/Action "$method" is invalid./);
return;
}
$c->app->log->debug(qq/Action "$method" is invalid./) and return
unless $method =~ /^[a-zA-Z0-9_:]+$/;

return $method;
}
Expand All @@ -495,9 +492,7 @@ sub _generate_route {
if (!ref $arg && !$pattern) { $pattern = $arg }

# Scalar
elsif (!ref $arg && @args) {
push @$conditions, $arg, shift @args;
}
elsif (!ref $arg && @args) { push @$conditions, $arg, shift @args }

# Last scalar is the route name
elsif (!ref $arg) { $name = $arg }
Expand Down
10 changes: 5 additions & 5 deletions t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -89,19 +89,19 @@ sub startup {

# /test3 (no class, just a namespace)
$r->route('/test3')
->to(namespace => 'MojoliciousTestController', method => 'index');
->to(namespace => 'MojoliciousTestController', action => 'index');

# /test2 (different namespace test)
$r->route('/test2')->to(
namespace => 'MojoliciousTest2',
class => 'Foo',
method => 'test'
namespace => 'MojoliciousTest2',
controller => 'Foo',
action => 'test'
);

# /test5 (only namespace test)
$r->route('/test5')->to(
namespace => 'MojoliciousTest2::Foo',
method => 'test'
action => 'test'
);

# /test6 (no namespace test)
Expand Down

0 comments on commit 6468750

Please sign in to comment.