SiteControl/PermissionManager.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 58 CC 3 SCAR 16.7
CC
3
Cov
0%
can
12.0
new
2.0
addRule
2.0
CRAP 5.3
1 package Apache2::SiteControl::PermissionManager;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6 use Carp;
7  
8 sub new {
9 my $proto = shift;
10 my $class = ref($proto) || $proto;
11 my $this = { rules => [] };
12 bless ($this, $class);
13 return $this;
14 }
15  
16 sub addRule($$)
17 {
18 my $this = shift;
19 my $rule = shift;
20  
21 push @{$this->{rules}}, $rule;
22  
23 return 1;
24 }
25  
26 sub can($$$$)
27 {
28 my $this = shift;
29 my $user = shift;
30 my $action = shift;
31 my $resource = shift;
32 my $rule;
33 my ($granted, $denied) = (0,0);
34  
35 for $rule (@{$this->{rules}})
36 {
37 $granted = 1 if($rule->grants($user, $action, $resource));
38 $denied = 1 if($rule->denies($user, $action, $resource));
39 }
40  
41 return ($granted && !$denied);
42 }
43  
44 1;
45  
46 __END__