Permalink
Browse files

deprecated render_exception and render_not_found methods in Mojolicio…

…us::Controller
  • Loading branch information...
kraih committed Jan 18, 2015
1 parent 28caa95 commit d964a84a453c0d32cfc358991e2911a71e08aab0
Showing with 39 additions and 30 deletions.
  1. +4 −0 Changes
  2. +5 −6 lib/Mojolicious.pm
  3. +2 −18 lib/Mojolicious/Controller.pm
  4. +27 −3 lib/Mojolicious/Plugin/DefaultHelpers.pm
  5. +1 −1 lib/Mojolicious/Routes.pm
  6. +0 −2 t/mojolicious/app.t
View
@@ -2,6 +2,10 @@
5.73 2015-01-18
- Deprecated Mojolicious::Routes::Route::bridge in favor of
Mojolicious::Routes::Route::under.
+ - Deprecated Mojolicious::Controller::render_exception in favor of
+ reply->exception helper.
+ - Deprecated Mojolicious::Controller::render_not_found in favor of
+ reply->not_found helper.
- Removed deprecated object-oriented Mojo::JSON API.
- Removed deprecated stringification support from Mojo::Collection.
- Removed deprecated support for data arguments from Mojo::JSON::Pointer.
View
@@ -108,7 +108,7 @@ sub dispatch {
# Routes
$plugins->emit_hook(before_routes => $c);
- $c->render_not_found
+ $c->helpers->reply->not_found
unless $tx->res->code || $self->routes->dispatch($c) || $tx->res->code;
}
@@ -154,10 +154,9 @@ sub new {
# Hide controller attributes/methods
$r->hide(qw(app continue cookie every_cookie every_param));
$r->hide(qw(every_signed_cookie finish flash helpers match on param));
- $r->hide(qw(redirect_to render render_exception render_later render_maybe));
- $r->hide(qw(render_not_found render_to_string rendered req res respond_to));
- $r->hide(qw(send session signed_cookie stash tx url_for validation write));
- $r->hide(qw(write_chunk));
+ $r->hide(qw(redirect_to render render_later render_maybe render_to_string));
+ $r->hide(qw(rendered req res respond_to send session signed_cookie stash));
+ $r->hide(qw(tx url_for validation write write_chunk));
# Check if we have a log directory that is writable
my $mode = $self->mode;
@@ -195,7 +194,7 @@ sub _exception {
my ($next, $c) = @_;
local $SIG{__DIE__}
= sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) };
- $c->render_exception($@) unless eval { $next->(); 1 };
+ $c->helpers->reply->exception($@) unless eval { $next->(); 1 };
}
1;
@@ -196,7 +196,8 @@ sub render {
return defined $output ? Mojo::ByteStream->new($output) : undef if $ts;
# Maybe
- return $maybe ? undef : !$self->render_not_found unless defined $output;
+ return $maybe ? undef : !$self->helpers->reply->not_found
+ unless defined $output;
# Prepare response
$plugins->emit_hook(after_render => $self, \$output, $format);
@@ -206,14 +207,10 @@ sub render {
return !!$self->rendered($self->stash->{status});
}
-sub render_exception { shift->helpers->reply->exception(@_) }
-
sub render_later { shift->stash('mojo.rendered' => 1) }
sub render_maybe { shift->render(@_, 'mojo.maybe' => 1) }
-sub render_not_found { shift->helpers->reply->not_found }
-
sub render_to_string { shift->render(@_, 'mojo.to_string' => 1) }
sub rendered {
@@ -680,13 +677,6 @@ L</"stash">.
# Render template "test.xml.*"
$c->render('test', format => 'xml');
-=head2 render_exception
-
- $c = $c->render_exception('Oops!');
- $c = $c->render_exception(Mojo::Exception->new('Oops!'));
-
-Alias for L<Mojolicious::Plugin::DefaultHelpers/"reply-E<gt>exception">.
-
=head2 render_later
$c = $c->render_later;
@@ -713,12 +703,6 @@ could be generated, takes the same arguments as L</"render">.
# Render template "index_local" only if it exists
$c->render_maybe('index_local') or $c->render('index');
-=head2 render_not_found
-
- $c = $c->render_not_found;
-
-Alias for L<Mojolicious::Plugin::DefaultHelpers/"reply-E<gt>not_found">.
-
=head2 render_to_string
my $output = $c->render_to_string('foo/index', format => 'pdf');
@@ -5,11 +5,27 @@ use Mojo::ByteStream;
use Mojo::Collection;
use Mojo::Exception;
use Mojo::IOLoop;
-use Mojo::Util qw(dumper sha1_sum steady_time);
+use Mojo::Util qw(deprecated dumper sha1_sum steady_time);
sub register {
my ($self, $app) = @_;
+ # DEPRECATED in Tiger Face!
+ $app->helper(
+ render_exception => sub {
+ deprecated 'Mojolicious::Controller::render_exception is DEPRECATED in'
+ . ' favor of the reply->exception helper';
+ shift->reply->exception(@_);
+ }
+ );
+ $app->helper(
+ render_not_found => sub {
+ deprecated 'Mojolicious::Controller::render_not_found is DEPRECATED in'
+ . ' favor of the reply->not_found helper';
+ shift->reply->not_found;
+ }
+ );
+
# Controller alias helpers
for my $name (qw(app flash param stash session url_for validation)) {
$app->helper($name => sub { shift->$name(@_) });
@@ -80,12 +96,20 @@ sub _delay {
my $c = shift;
my $tx = $c->render_later->tx;
my $delay = Mojo::IOLoop->delay(@_);
- $delay->catch(sub { $c->render_exception(pop) and undef $tx })->wait;
+ $delay->catch(sub { $c->helpers->reply->exception(pop) and undef $tx })
+ ->wait;
}
sub _development {
my ($page, $c, $e) = @_;
+ # DEPRECATED in Tiger Face!
+ if (my $sub = $c->can("render_$page")) {
+ deprecated "Mojolicious::Controller::render_$page is DEPRECATED in favor"
+ . " of the reply->$page helper";
+ return $c->$sub($page eq 'exception' ? $e : ());
+ }
+
my $app = $c->app;
$app->log->error($e = Mojo::Exception->new($e)) if $page eq 'exception';
@@ -141,7 +165,7 @@ sub _static {
my ($c, $file) = @_;
return !!$c->rendered if $c->app->static->serve($c, $file);
$c->app->log->debug(qq{File "$file" not found, public directory missing?});
- return !$c->render_not_found;
+ return !$c->helpers->reply->not_found;
}
sub _url_with {
@@ -21,7 +21,7 @@ sub auto_render {
my ($self, $c) = @_;
my $stash = $c->stash;
return if $stash->{'mojo.rendered'};
- $c->render_maybe or $stash->{'mojo.routed'} or $c->render_not_found;
+ $c->render_maybe or $stash->{'mojo.routed'} or $c->helpers->reply->not_found;
}
sub continue {
View
@@ -115,10 +115,8 @@ ok $t->app->routes->is_hidden('on'), 'is hidden';
ok $t->app->routes->is_hidden('param'), 'is hidden';
ok $t->app->routes->is_hidden('redirect_to'), 'is hidden';
ok $t->app->routes->is_hidden('render'), 'is hidden';
-ok $t->app->routes->is_hidden('render_exception'), 'is hidden';
ok $t->app->routes->is_hidden('render_later'), 'is hidden';
ok $t->app->routes->is_hidden('render_maybe'), 'is hidden';
-ok $t->app->routes->is_hidden('render_not_found'), 'is hidden';
ok $t->app->routes->is_hidden('render_to_string'), 'is hidden';
ok $t->app->routes->is_hidden('rendered'), 'is hidden';
ok $t->app->routes->is_hidden('req'), 'is hidden';

0 comments on commit d964a84

Please sign in to comment.