| 1 | package App::ZofCMS::Plugin::AccessDenied; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub new { return bless {}, shift } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 0 | my ( $self, $t, $q, $config ) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | $t->{plug_access_denied} | ||||||||||||||||||||||||||||
| 14 | = $t->{plug_access_denied}->( $t, $q, $config ) | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | if ref $t->{plug_access_denied} eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | $config->conf->{plug_access_denied} | ||||||||||||||||||||||||||||
| 18 | = $config->conf->{plug_access_denied}->( $t, $q, $config ) | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ref $config->conf->{plug_access_denied} eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | my %conf = ( | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | role => sub { $_[0]->{d}{user}{role} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | separator => qr/\s*,\s*/, | ||||||||||||||||||||||||||||
| 24 | key => 'access_roles', | ||||||||||||||||||||||||||||
| 25 | redirect_page => '/access-denied', | ||||||||||||||||||||||||||||
| 26 | master_roles => 'admin', | ||||||||||||||||||||||||||||
| 27 | no_exit => 0, | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | %{ delete $config->conf->{plug_access_denied} || {} }, | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $config->conf->{'plug_access_denied'} || {}
MC/DC0%0/1
delete $config->conf->{'plug_access_denied'} || {}
delete $config->conf->{'plug_access_denied'}
Truth table0%0/2
A
A= delete $config->conf->{'plug_access_denied'}
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | %{ delete $t->{plug_access_denied} || {} }, | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $t->{'plug_access_denied'} || {}
MC/DC0%0/1
delete $t->{'plug_access_denied'} || {}
delete $t->{'plug_access_denied'}
Truth table0%0/2
A
A= delete $t->{'plug_access_denied'}
| |||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | return | ||||||||||||||||||||||||||||
| 34 | unless defined $t->{ $conf{key} } | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | and length $t->{ $conf{key} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $$t{$conf{"key"}} and length $$t{$conf{"key"}}
MC/DC0%0/2
defined $$t{$conf{"key"}} and length $$t{$conf{"key"}}
defined $$t{$conf{"key"}}
length $$t{$conf{"key"}}
Truth table0%0/3
A and B
A= defined $$t{$conf{"key"}}B= length $$t{$conf{"key"}}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $user_role_raw = $conf{role}->( $t, $q, $config ); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | $user_role_raw = $user_role_raw->( $t, $q, $config ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | if ref $user_role_raw eq 'CODE'; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $user_roles = prepare_user_roles( \%conf, $user_role_raw ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | for ( split /$conf{separator}/, $conf{master_roles} ) { | |||||||||||||||||||||||||||
| 44 | return 1 | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if $user_roles->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | for ( split /$conf{separator}/, $t->{ $conf{key} } ) { | |||||||||||||||||||||||||||
| 49 | return 1 | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if exists $user_roles->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | print $config->cgi->redirect( $conf{redirect_page} ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | exit | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless $conf{no_exit}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub prepare_user_roles { | ||||||||||||||||||||||||||
|
Subroutine
prepare_user_roles: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ( $conf, $user_role_raw ) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | my %roles; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( ref $user_role_raw eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | 0 | %roles = map +( $_ => 1 ), @$user_role_raw; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | elsif ( ref $user_role_raw eq 'HASH' ) { | ||||||||||||||||||||||||||||
| 67 | 0 | %roles = map +( $_ => 1 ), keys %$user_role_raw; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||
| 70 | 0 | %roles | |||||||||||||||||||||||||||
| 71 | = map +( $_ => 1 ), split /$conf->{separator}/, $user_role_raw; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | return \%roles; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||