Before Mason Runs
- Dispatching to Mason has a cost.
- Mason has to translate the URI to a component.
- Load the component
- Execute it
- If your component will just issue a redirect, why not do that without Mason?
- For example, you can do access checks before Mason.
- Enter MasonX::WebApp:
package My::WebApp;
use base 'MasonX::WebApp';
sub _init {
my $self = shift;
$self->_check_auth;
}
sub _check_auth {
my $self = shift;
if ( $self->apache_req->uri =~ m{^/admin} ) {
$self->_require_admin;
}
}
sub _require_admin {
my $self = shift;
$self->redirect( uri => '/' )
unless $self->current_user->is_admin;
}