package steffen::MojoPlug::Authorization;
use parent 'Mojolicious::Plugin::Authorization';

our $VERSION = '__VERSION__';

sub register {
    my ($self, $app, $args) = @_;

    my $verbose = $args->{verbose} || 0;

    $args->{has_priv} = sub {
        my ($self, $priv, $xtra) = @_;
        #$self->app->log->debug('has_priv') if $verbose;
        return grep { /$priv/ } @{$self->session->{privs}};
    };

    $args->{is_role} = sub {
        my ($self, $role, $xtra) = @_;
        #$self->app->log->debug('is_role') if $verbose;
        return $role eq $self->session->{role};
    };

    $args->{user_privs} = sub {
        my ($self, $xtra) = @_;
        #$self->app->log->debug('user_privs') if $verbose;
        return $self->session->{privs};
    };

    $args->{user_role} = sub {
        my ($self, $xtra) = @_;
        #$self->app->log->debug('user_role') if $verbose;
        return $self->session->{role};
    };

    $self->SUPER::register($app, $args);
    $app->log->info(sprintf('REGISTERED: %s %s', __PACKAGE__, q$Revision: 86 $)) if $verbose;
}

1;
