blib/lib/OpusVL/AppKit/Plugin/AppKit/FeatureList.pm

filter: Statementstmt 100% 59 / 59 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 94.7% 90 / 95 CC 11 SCAR 10.3
CC
11
Cov
96%
add_action
4.0
feature_list
4.0
roles_allowed_for_action
3.0
CRAP 2.8
« blib/lib/OpusVL/AppKit/LDAPAuth.pm ↑ Summary lib/OpusVL/AppKit/Controller/Root.pm »
1 package OpusVL::AppKit::Plugin::AppKit::FeatureList;
2  
3  
4 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶has _features => ( is => 'rw' , isa => 'HashRef', default => sub { {}; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
7 8 ▶has _path_to_feature => ( is => 'rw' , isa => 'HashRef', default => sub { {}; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 sub add_action
10 346 ▶{
Subroutine add_action: called CC=4 SCAR=13.9
Pod documented
11 346 my $self = shift;
12 346 my $app = shift;
13 346 my $action = shift;
14  
15 346 my $features = $action->attributes->{AppKitFeature};
16 346 ▶ return if !$features || !@$features;
Branch: 1 branch
BranchTrueFalseTotal
unless $features and @$features 98 248 346
Condition66%2/3
$features and @$features
!ll&&!rl&&r
980248
MC/DC50%1/2
$features and @$features
$features @$features
Truth table66%2/3
A and B
A= $featuresB= @$features
ABresult
0X0
100
111
17 248 my $list = $features->[0];
18 248 my @features = split /,/, $list;
19 248 for my $feature (@features)
20 {
21 269 $self->_add_to_feature($app .'/'. $feature, $action->reverse);
22 }
23 248 my @app_and_feature = map { $app .'/'. $_ } @features;
24 248 $self->_path_to_feature->{$action->reverse} = \@app_and_feature;
25 }
26  
27 sub _add_to_feature
28 269 ▶{
Subroutine _add_to_feature: called CC=2 SCAR=6.9
29 269 my ($self, $feature, $action) = @_;
30  
31 269 ▶ if(!defined $self->_features->{$feature})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_features->{$feature}) 79 190 269
32 {
33 79 $self->_features->{$feature} = { actions => [], roles_allowed => [] };
34 }
35 269 push @{$self->_features->{$feature}->{actions}}, $action;
36 }
37  
38 sub set_roles_allowed
39 78 ▶{
Subroutine set_roles_allowed: called CC=2 SCAR=7.1
Pod documented
40 78 my ($self, $feature, $roles) = @_;
41  
42 78 my $f = $self->_features->{$feature};
43 78 ▶ $f->{roles_allowed} = $roles if $f;
Branch: 1 branch
BranchTrueFalseTotal
if $f 78 0 78
44 }
45  
46 sub roles_allowed_for_action
47 460 ▶{
Subroutine roles_allowed_for_action: called CC=3 SCAR=11.0
Pod documented
48 460 my $self = shift;
49 460 my $action_path = shift;
50  
51 460 my $features = $self->_path_to_feature->{$action_path};
52 460 ▶ return [] if !$features || !@$features;
Branch: 1 branch
BranchTrueFalseTotal
unless $features and @$features 119 341 460
Condition66%2/3
$features and @$features
!ll&&!rl&&r
1190341
MC/DC50%1/2
$features and @$features
$features @$features
Truth table66%2/3
A and B
A= $featuresB= @$features
ABresult
0X0
100
111
53 341 my @roles = map { @{$self->_features->{$_}->{roles_allowed} } } @$features;
54 341 return \@roles;
55 }
56  
57 sub feature_list
58 13 ▶{
Subroutine feature_list: called CC=4 SCAR=13.9
Pod documented
59 13 my $self = shift;
60 13 my $current_role = shift;
61  
62 # return a list of Feature name -> [roles allowed]
63 13 my %map;
64 13 my @keys = keys %{$self->_features};
65 13 ▶ if($current_role)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_role) { } 8 5 13
66 {
67 # filter it down to a yes/no type deal.
68 8 %map = map { $_ => scalar grep { $current_role eq $_ } @{$self->_features->{$_}->{roles_allowed}} } @keys;
69 }
70 else
71 {
72 5 %map = map { $_ => $self->_features->{$_}->{roles_allowed} } @keys;
73 }
74 # now split the map up some more.
75 13 my %apps;
76 13 for my $key (sort keys %map)
77 {
78 74 $key =~ q|^(.*)/(.*)$|;
79 74 ▶ $apps{$1} = {} if !defined $apps{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $apps{$1} 31 43 74
80 74 $apps{$1}->{$2} = $map{$key};
81 }
82 13 return \%apps;
83 }
84  
85 sub feature_names_with_app
86 7 ▶{
Subroutine feature_names_with_app: called CC=1 SCAR=0.0
Pod documented
87 7 my $self = shift;
88 7 my %map;
89 7 my @keys = keys %{$self->_features};
90 7 return \@keys;
91 }
92  
93 11 1;
94  
95 __END__
« blib/lib/OpusVL/AppKit/LDAPAuth.pm ↑ Summary lib/OpusVL/AppKit/Controller/Root.pm »