NAME
Mojolicious::Plugin::AdvancedMod::ActionFilter - Analogue of Rails: before_filter, after_filter
METHOD
action_filter
$self->action_filter( filter_name => sub { ... } );
SYNOPSIS
# Main app file
sub startup {
my $self = shift;
...
$self->action_filter(
is_auth => sub { shift->render( text => "is_auth filter" ) },
test => sub { shift->render( text => "test before_filter" ); },
);
}
# Controller
our $BEFORE_FILTERS = { is_auth => [qw/show/] };
our $AFTER_FILTERS = { test => [qw/show/] };
sub show {
my ( $self, $filter, $action ) = @_;
$self->render( text => 'show action' );
}
sub index {
my $self = shift;
$self->render( text => 'index action' );
}
# Log
[info] Applying before_filter is_auth for example#show
[info] Applying after_filter test for example#show
[debug] GET "/show".
AUTHOR
Grishkovelli grishkovelli@gmail.com
https://github.com/grishkovelli/Mojolicious-Plugin-AdvancedMod
COPYRIGHT AND LICENSE
Copyright (C) 2013, 2014 Grishkovelli grishkovelli@gmail.com
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.