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

filter: Statementstmt 90.8% 79 / 87 Branchbran 75.0% 24 / 32 Conditioncond 75.0% 9 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 84.3% 124 / 147 CC 23 SCAR 23.9
CC
23
Cov
85%
merge_controller_actions
14.7
__ANON__
10.7
BEGIN
1.0
CRAP 11.0
« blib/lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/Role.pm ↑ Summary lib/OpusVL/AppKit/RolesFor/Controller/GUI.pm »
1 package OpusVL::AppKit::Plugin::AppKitControllerSorter;
2  
3  
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 $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 {
17 10 ▶ my ($self, @args) = @_;
Subroutine __ANON__: called CC=10 SCAR=23.7
18  
19 24 my %appkitconntrollers = map { my $controller = $self->controller($_); ref $controller => $controller }
20 10 ▶ grep { $self->controller($_)->can('appkit') && $self->controller($_)->home_action} $self->controllers;
Branch: 1 branch
BranchTrueFalseTotal
$self->controller($_)->can("appkit") and $self->controller($_)->home_action 96 10 106
21 10 my @list;
22 10 my $setting = $self->config->{appkit_app_order};
23 10 ▶ @list = @$setting if $setting;
Branch: 1 branch
BranchTrueFalseTotal
if $setting 8 2 10
24 10 my $count = scalar @list;
25 10 ▶ if($count && $count < scalar keys %appkitconntrollers)
Branch: 1 branch
BranchTrueFalseTotal
if ($count and $count < scalar keys %appkitconntrollers) 0 10 10
Condition66%2/3
$count and $count < scalar keys %appkitconntrollers
!ll&&!rl&&r
280
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
ABresult
0X0
100
111
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 10 ▶ for(my $i = 0; $i < $count; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 24 10 34
31 {
32 24 my $class = $list[$i];
33 24 my $controller = $appkitconntrollers{$class};
34 24 ▶ if($controller)
Branch: 1 branch
BranchTrueFalseTotal
if ($controller) { } 24 0 24
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 10 ▶ if(!$count)
Branch: 1 branch
BranchTrueFalseTotal
unless ($count) 2 8 10
44 {
45 # if there wasn't a config setting for order do the default alphabetical sort.
46 2 my @default_sort = sort { $a->appkit_name cmp $b->appkit_name } values %appkitconntrollers;
47 2 $count = scalar @default_sort;
48 2 ▶ for(my $i = 0; $i < $count; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 2 2
49 {
50 0 $default_sort[$i]->appkit_order($i);
51 }
52 }
53 10 my @all_controllers = map { $self->controller($_) } grep { $self->controller($_)->can('appkit') } $self->controllers;
54 10 for my $controller (@all_controllers)
55 {
56 96 $self->merge_controller_actions($controller, \@all_controllers);
57 }
58 11 };
59  
60  
61 sub merge_controller_actions
62 {
63 96 ▶ my $self = shift;
Subroutine merge_controller_actions: called CC=14 SCAR=26.8
Pod documented
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
BranchTrueFalseTotal
unless $controller->does("OpusVL::AppKit::RolesFor::Controller::GUI") 0 96 96
68 96 my @navItems = @{$controller->navigation_actions};
69 96 ▶ @navItems = () if(!@navItems);
Branch: 1 branch
BranchTrueFalseTotal
unless @navItems 64 32 96
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
BranchTrueFalseTotal
if ($controller->appkit_shared_module and not $controller->navigation_items_merged) 24 72 96
Condition66%2/3
$controller->appkit_shared_module and not $controller->navigation_items_merged
!ll&&!rl&&r
72024
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
ABresult
0X0
100
111
80 {
81 24 my $controllers = $appkit_controllers;
82 24 for my $c (@$controllers)
83 {
84 241 ▶ if($c != $controller && $c->does('OpusVL::AppKit::RolesFor::Controller::GUI'))
Branch: 1 branch
BranchTrueFalseTotal
if ($c != $controller and $c->does("OpusVL::AppKit::RolesFor::Controller::GUI")) 225 16 241
Condition66%2/3
$c != $controller and $c->does("OpusVL::AppKit::RolesFor::Controller::GUI")
!ll&&!rl&&r
160225
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")
ABresult
0X0
100
111
85 {
86 225 ▶ if($c->appkit_shared_module && $c->appkit_shared_module eq $controller->appkit_shared_module)
Branch: 1 branch
BranchTrueFalseTotal
if ($c->appkit_shared_module and $c->appkit_shared_module eq $controller->appkit_shared_module) 16 209 225
Condition100%3/3
$c->appkit_shared_module and $c->appkit_shared_module eq $controller->appkit_shared_module
!ll&&!rl&&r
1822716
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
ABresult
0X0
100
111
87 {
88 16 ▶ if($c->navigation_items_merged)
Branch: 1 branch
BranchTrueFalseTotal
if ($c->navigation_items_merged) 8 8 16
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
BranchTrueFalseTotal
if ($group) { } 0 8 8
100 {
101 0 ▶ push @{$group->{actions}}, @{$c->navigation_actions} if $c->navigation_actions;
Branch: 1 branch
BranchTrueFalseTotal
if $c->navigation_actions 0 0 0
102 }
103 else
104 {
105 8 my @copy = @{$c->navigation_actions};
106 8 ▶ $group_process->{ $c->appkit_method_group } = {
Branch: 1 branch
BranchTrueFalseTotal
if $c->navigation_actions 8 0 8
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 233 @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 11 1;
129  
130 __END__
131  
132 =pod
133  
134 =encoding UTF-8
135  
136 =head1 NAME
137  
138 OpusVL::AppKit::Plugin::AppKitControllerSorter
139  
140 =head1 VERSION
141  
142 version 2.24
143  
144 =head2 merge_controller_actions
145 Looks at other controllers in the app to see if any of the navigation actions
146 need to be merged up together. This allows us to have multiple controllers
147 that are all part of the same module.
148  
149 This is called by the template to ensure the parts are merged up before we
150 go on.
151  
152 =head1 AUTHOR
153  
154 OpusVL - www.opusvl.com
155  
156 =head1 COPYRIGHT AND LICENSE
157  
158 This software is copyright (c) 2010 by OpusVL - www.opusvl.com.
159  
160 This is free software; you can redistribute it and/or modify it under
161 the same terms as the Perl 5 programming language system itself.
162  
163 =cut
« blib/lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/Role.pm ↑ Summary lib/OpusVL/AppKit/RolesFor/Controller/GUI.pm »