| 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
Condition66%2/3
$features and @$features
MC/DC50%1/2
$features and @$features
$features
@$features
Truth table66%2/3
A and B
A= $featuresB= @$features
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$features and @$features
MC/DC50%1/2
$features and @$features
$features
@$features
Truth table66%2/3
A and B
A= $featuresB= @$features
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||