SiteControl/PermissionManager.pm untested

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