| 1 | package OpusVL::AppKit::Plugin::AppKitControllerSorter; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 9 | $VERSION = '1.000'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # this plugin takes the appkit_app_order config setting and sets it against the controllers. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | after setup_finalize => sub | ||||||||||||||||||||||||||||
| 16 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.7
| |||||||||||||||||||||||||||||
| 17 | 9 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 24 | my %appkitconntrollers = map { my $controller = $self->controller($_); ref $controller => $controller } | |||||||||||||||||||||||||||
| 20 | 9 | ▶ | grep { $self->controller($_)->can('appkit') && $self->controller($_)->home_action} $self->controllers; | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->controller($_)->can('appkit') && $self->controller($_)->home_action
MC/DC100%2/2
$self->controller($_)->can('appkit') && $self->controller($_)->home_action
$self->controller($_)->can('appkit')
$self->controller($_)->home_action
Truth table100%3/3
A && B
A= $self->controller($_)->can('appkit')B= $self->controller($_)->home_action
| |||||||||||||||||||||||||||||
| 21 | 9 | my @list; | |||||||||||||||||||||||||||
| 22 | 9 | my $setting = $self->config->{appkit_app_order}; | |||||||||||||||||||||||||||
| 23 | 9 | ▶ | @list = @$setting if $setting; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 9 | my $count = scalar @list; | |||||||||||||||||||||||||||
| 25 | 9 | ▶ | if($count && $count < scalar keys %appkitconntrollers) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count and $count < scalar keys %appkitconntrollers
MC/DC0%0/2
$count and $count < scalar keys %appkitconntrollers
$count
$count < scalar keys %appkitconntrollers
Truth table66%2/3
A and B
A= $countB= $count < scalar keys %appkitconntrollers
| |||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 0 | $self->log->warn('Application order is not completely set. Update your appkit_app_order config setting'); | |||||||||||||||||||||||||||
| 28 | 0 | $self->log->warn('Expecting these controllers to be specified ' . join ', ', keys %appkitconntrollers); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 9 | ▶ | for(my $i = 0; $i < $count; $i++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 24 | my $class = $list[$i]; | |||||||||||||||||||||||||||
| 33 | 24 | my $controller = $appkitconntrollers{$class}; | |||||||||||||||||||||||||||
| 34 | 24 | ▶ | if($controller) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 24 | $controller->appkit_order($i); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | $self->log->warn("appkit_app_order mentions class $class which doesn't appear to be loaded."); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 9 | ▶ | if(!$count) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | # if there wasn't a config setting for order do the default alphabetical sort. | ||||||||||||||||||||||||||||
| 46 | 0 | my @default_sort = sort { $a->appkit_name cmp $b->appkit_name } values %appkitconntrollers; | |||||||||||||||||||||||||||
| 47 | 1 | $count = scalar @default_sort; | |||||||||||||||||||||||||||
| 48 | 1 | ▶ | for(my $i = 0; $i < $count; $i++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | $default_sort[$i]->appkit_order($i); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 9 | my @all_controllers = map { $self->controller($_) } grep { $self->controller($_)->can('appkit') } $self->controllers; | |||||||||||||||||||||||||||
| 54 | 9 | for my $controller (@all_controllers) | |||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | 96 | $self->merge_controller_actions($controller, \@all_controllers); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 9 | }; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub merge_controller_actions | ||||||||||||||||||||||||||||
| 62 | 96 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
merge_controller_actions: called CC=14 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 96 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 96 | my $controller = shift; | |||||||||||||||||||||||||||
| 65 | 96 | my $appkit_controllers = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 96 | ▶ | return [] if !$controller->does('OpusVL::AppKit::RolesFor::Controller::GUI'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 96 | my @navItems = @{$controller->navigation_actions}; | |||||||||||||||||||||||||||
| 69 | 96 | ▶ | @navItems = () if(!@navItems); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 96 | my @second = @navItems; | |||||||||||||||||||||||||||
| 71 | 96 | my $group_process = { | |||||||||||||||||||||||||||
| 72 | $controller->appkit_method_group => { | ||||||||||||||||||||||||||||
| 73 | group => $controller->appkit_method_group, | ||||||||||||||||||||||||||||
| 74 | order => $controller->appkit_method_group_order, | ||||||||||||||||||||||||||||
| 75 | actions => \@second } | ||||||||||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||||||||||
| 77 | 96 | my @grouped; | |||||||||||||||||||||||||||
| 78 | 96 | @grouped = ( $group_process->{$controller->appkit_method_group} ); | |||||||||||||||||||||||||||
| 79 | 96 | ▶ | if($controller->appkit_shared_module && !$controller->navigation_items_merged) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$controller->appkit_shared_module and not $controller->navigation_items_merged
MC/DC50%1/2
$controller->appkit_shared_module and not $controller->navigation_items_merged
$controller->appkit_shared_module
not $controller->navigation_items_merged
Truth table66%2/3
A and not(B)
A= $controller->appkit_shared_moduleB= not $controller->navigation_items_merged
| |||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 24 | my $controllers = $appkit_controllers; | |||||||||||||||||||||||||||
| 82 | 24 | for my $c (@$controllers) | |||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 226 | ▶ | if($c != $controller && $c->does('OpusVL::AppKit::RolesFor::Controller::GUI')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c != $controller and $c->does("OpusVL::AppKit::RolesFor::Controller::GUI")
MC/DC50%1/2
$c != $controller and $c->does("OpusVL::AppKit::RolesFor::Controller::GUI")
$c != $controller
$c->does("OpusVL::AppKit::RolesFor::Controller::GUI")
Truth table66%2/3
A and B
A= $c != $controllerB= $c->does("OpusVL::AppKit::RolesFor::Controller::GUI")
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 210 | ▶ | if($c->appkit_shared_module && $c->appkit_shared_module eq $controller->appkit_shared_module) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c->appkit_shared_module and $c->appkit_shared_module eq $controller->appkit_shared_module
MC/DC100%2/2
$c->appkit_shared_module and $c->appkit_shared_module eq $controller->appkit_shared_module
$c->appkit_shared_module
$c->appkit_shared_module eq $controller->appkit_shared_module
Truth table100%3/3
A and B
A= $c->appkit_shared_moduleB= $c->appkit_shared_module eq $controller->appkit_shared_module
| |||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 16 | ▶ | if($c->navigation_items_merged) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | # we've alraedy done the merge when we did this controller | ||||||||||||||||||||||||||||
| 91 | # so just short cut the process. | ||||||||||||||||||||||||||||
| 92 | # and use it's result. | ||||||||||||||||||||||||||||
| 93 | 8 | @navItems = @{$c->navigation_actions}; | |||||||||||||||||||||||||||
| 94 | 8 | @grouped = @{$c->navigation_actions_grouped}; | |||||||||||||||||||||||||||
| 95 | 8 | last; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 8 | push @navItems, @{$c->navigation_actions}; | |||||||||||||||||||||||||||
| 98 | 8 | my $group = $group_process->{$c->appkit_method_group}; | |||||||||||||||||||||||||||
| 99 | 8 | ▶ | if($group) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | push @{$group->{actions}}, @{$c->navigation_actions} if $c->navigation_actions; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else | ||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 8 | my @copy = @{$c->navigation_actions}; | |||||||||||||||||||||||||||
| 106 | 8 | ▶ | $group_process->{ $c->appkit_method_group } = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | group => $c->appkit_method_group, | ||||||||||||||||||||||||||||
| 108 | order => $c->appkit_method_group_order, | ||||||||||||||||||||||||||||
| 109 | actions => \@copy, | ||||||||||||||||||||||||||||
| 110 | } if($c->navigation_actions); | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | # FIXME: figure out what this does because I've forgoten now. | ||||||||||||||||||||||||||||
| 115 | # sort the group | ||||||||||||||||||||||||||||
| 116 | 218 | @grouped = map { $group_process->{$_} } sort { $group_process->{$a}->{order} <=> $group_process->{$b}->{order} } keys %$group_process; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | # sort the items so that they appear | ||||||||||||||||||||||||||||
| 120 | # in a consistent order regardless of controller. | ||||||||||||||||||||||||||||
| 121 | 24 | my @sorted = sort { $a->{actionpath} cmp $b->{actionpath} } @navItems; | |||||||||||||||||||||||||||
| 122 | 24 | $controller->navigation_actions( \@sorted ); | |||||||||||||||||||||||||||
| 123 | 24 | $controller->navigation_actions_grouped( \@grouped ); | |||||||||||||||||||||||||||
| 124 | 24 | $controller->navigation_items_merged(1); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 9 | 1; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||