ZofCMS/Plugin/AccessDenied.pm

filter: Statementstmt 24.2% 8 / 33 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 2 / 6 Podpod 0.0% 0 / 3 totaltotal 14.0% 10 / 71 CC 15 SCAR 47.9
CC
15
Cov
14%
process
182.0
prepare_user_roles
12.0
new
2.0
CRAP 120.4
« ZofCMS/Plugin/Barcode.pm ↑ Summary ZofCMS/Plugin/Tagged.pm »
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
BranchTrueFalseTotal
if ref $t->{"plug_access_denied"} eq "CODE" 0 0 0
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
BranchTrueFalseTotal
if ref $config->conf->{"plug_access_denied"} eq "CODE" 0 0 0
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'} || {}
l!l
00
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'}
Aresult
11
00
30 0 ▶ %{ delete $t->{plug_access_denied} || {} },
Condition0%0/2
delete $t->{'plug_access_denied'} || {}
l!l
00
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'}
Aresult
11
00
31 );
32  
33 return
34 unless defined $t->{ $conf{key} }
35 0 ▶ and length $t->{ $conf{key} };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$t{$conf{"key"}} and length $$t{$conf{"key"}} 0 0 0
Condition0%0/3
defined $$t{$conf{"key"}} and length $$t{$conf{"key"}}
!ll&&!rl&&r
000
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"}}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ref $user_role_raw eq "CODE" 0 0 0
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
BranchTrueFalseTotal
if $user_roles->{$_} 0 0 0
46 }
47  
48 0 for ( split /$conf{separator}/, $t->{ $conf{key} } ) {
49 return 1
50 0 ▶ if exists $user_roles->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $user_roles->{$_} 0 0 0
51 }
52  
53 0 print $config->cgi->redirect( $conf{redirect_page} );
54  
55 exit
56 0 ▶ unless $conf{no_exit};
Branch: 1 branch
BranchTrueFalseTotal
unless $conf{"no_exit"} 0 0 0
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
BranchTrueFalseTotal
if (ref $user_role_raw eq 'ARRAY') { } 0 0 0
elsif (ref $user_role_raw eq 'HASH') { } 0 0 0
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__
« ZofCMS/Plugin/Barcode.pm ↑ Summary ZofCMS/Plugin/Tagged.pm »