Permalink
Browse files

made all Mojolicious after_* plugin hooks run in reverse order

  • Loading branch information...
1 parent dcc26a4 commit e8e3c1f18d3dd22ddb83c7be703d4bcac7b19a51 Sebastian Riedel committed Jan 11, 2010
Showing with 23 additions and 3 deletions.
  1. +1 −0 Changes
  2. +3 −3 lib/Mojolicious.pm
  3. +19 −0 lib/Mojolicious/Plugins.pm
View
@@ -25,6 +25,7 @@ This file documents the revision history for Perl extension Mojo.
- Added version command.
- Added after_build_tx plugin hook.
- Added timer support to Mojo::IOLoop.
+ - Made all Mojolicious after_* plugin hooks run in reverse order.
- Made param decoding more defensive and allow malformed data to pass
through for debugging.
- Reduced Mojolicious log output outside of development mode.
View
@@ -33,7 +33,7 @@ sub new {
my $tx = Mojo::Transaction::Single->new;
# Hook
- $self->plugins->run_hook(after_build_tx => $tx);
+ $self->plugins->run_hook_reverse(after_build_tx => $tx);
return $tx;
}
@@ -100,7 +100,7 @@ sub dispatch {
my $e = $self->static->dispatch($c);
# Hook
- $self->plugins->run_hook(after_static_dispatch => $c);
+ $self->plugins->run_hook_reverse(after_static_dispatch => $c);
# Use routes if we don't have a response yet
$e = $self->routes->dispatch($c) if $e;
@@ -112,7 +112,7 @@ sub dispatch {
elsif ($e) { $c->render_not_found }
# Hook
- $self->plugins->run_hook(after_dispatch => $c);
+ $self->plugins->run_hook_reverse(after_dispatch => $c);
}
# Bite my shiny metal ass!
View
@@ -87,6 +87,20 @@ sub run_hook {
return $self;
}
+sub run_hook_reverse {
+ my $self = shift;
+
+ # Shortcut
+ my $name = shift;
+ return $self unless $name;
+ return unless $self->hooks->{$name};
+
+ # Run
+ $self->$_(@_) for reverse @{$self->hooks->{$name}};
+
+ return $self;
+}
+
1;
__END__
@@ -136,4 +150,9 @@ implements the following new ones.
$plugins = $plugins->run_hook('foo');
$plugins = $plugins->run_hook(foo => 123);
+=head2 C<run_hook_reverse>
+
+ $plugins = $plugins->run_hook_reverse('foo');
+ $plugins = $plugins->run_hook_reverse(foo => 123);
+
=cut

0 comments on commit e8e3c1f

Please sign in to comment.