Introduction to Mason 27

Before Mason Runs: MasonX::Interp::WithCallbacks (cont)

sub get_user : PreCallback( priority => 1 )
{
    my $self = shift;

    $self->params->{user} = $self->_get_user_from_cookie;
}

sub check_auth : PreCallback( priority => 2 )
{
    my $self = shift;

    if ( $self->params->{apache_req}->uri =~ m{^/admin} )
    {
        $self->_require_admin;
    }
}

sub _require_admin
{
    my $self = shift;

    $self->redirect('/')
        unless $self->params->{user}->is_admin;
}