Introduction to Mason 23

Before Mason Runs

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;
}