lib/CallBackery/GuiPlugin/AbstractAction.pm

filter: Statementstmt 71.4% 70 / 98 Branchbran 58.8% 20 / 34 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.8% 11 / 19 Podpod 100% 1 / 1 totaltotal 62.6% 104 / 166 CC 24 SCAR 22.2
CC
24
Cov
65%
__ANON__
30.0
__fixActionCfg
12.3
massageConfig
9.7
CRAP 9.2
« lib/CallBackery/GuiPlugin/Users.pm ↑ Summary blib/lib/CallBackery/GuiPlugin/AbstractCardlist.pm »
1 package CallBackery::GuiPlugin::AbstractAction;
2 14 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use CallBackery::Translate qw(trm);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use CallBackery::Exception qw(mkerror);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Mojo::Promise;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Mojo::JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use Mojo::Util qw(dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 CallBackery::GuiPlugin::AbstractAction - action form base class
12  
13 =head1 SYNOPSIS
14  
15 use Mojo::Base 'CallBackery::GuiPlugin::AbstractAction';
16  
17 =head1 DESCRIPTION
18  
19 The base class for gui forms with actions.
20  
21 =cut
22  
23 14 ▶use Mojo::Base 'CallBackery::GuiPlugin::Abstract', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 =head1 ATTRIBUTES
26  
27 The attributes of the L<CallBackery::GuiPlugin::Abstract> class plus:
28  
29 =head2 screenCfg
30  
31 Returns a configuration structure for the form. The output from this
32 method is fed to the callbackery.ui.form.Auto object to build the
33 Qooxdoo form.
34  
35 =cut
36  
37 0 ▶has screenCfg => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 my $self = shift;
39 0 $self->__fixActionCfg;
40 return {
41 0 type => 'action',
42 options => $self->screenOpts,
43 action => $self->actionCfg,
44 }
45 14 };
46  
47 # if no user is assigned, all access checks are positive, this allows to explore the
48 # modules full capabilities during startup
49 48 ▶has 'user'=> sub ($self) {
Subroutine __ANON__: called CC=6 SCAR=18.1
50 48 my $mockUser = bless {}, 'MockUser';
51 48 ▶ unless (defined &MockUser::may) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &MockUser::may) 11 37 48
52 12 ▶ *MockUser::may = sub ($mockSelf, $right) {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 # $self->log->debug("MockUser::may($right) -> true");
54 12 return 1;
55 11 };
56 }
57 48 ▶ unless (defined &MockUser::mayAny) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &MockUser::mayAny) 11 37 48
58 0 ▶ *MockUser::mayAny = sub ($mockSelf, $right) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 # $self->log->debug("MockUser::may($right) -> true");
60 0 return 1;
61 11 };
62 }
63 48 ▶ unless (defined &MockUser::userId) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &MockUser::userId) 11 37 48
64 0 ▶ *MockUser::userId = sub ($mockSelf) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 return '__MockUser__';
66 11 };
67 }
68 48 ▶ unless (defined &MockUser::userInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &MockUser::userInfo) 11 37 48
69 0 ▶ *MockUser::userInfo = sub ($mockSelf) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 return {};
71 11 };
72 }
73 48 ▶ unless (defined &MockUser::controller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &MockUser::controller) 11 37 48
74 0 ▶ *MockUser::controller = sub ($mockSelf) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 return undef;
76 11 };
77 }
78 48 return $mockUser;
79 14 };
80  
81 =head2 screenOpts
82  
83 Returns a hash of options for the screen Options
84  
85 =cut
86  
87 0 ▶has screenOpts => sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
88 {
89 }
90 0 };
91  
92 =head2 actionCfg
93  
94 Returns a list of action buttons to place at the top of the form.
95  
96 For C<download> and C<display> actions the gui is blocked by a modal busy
97 indicator while the download is being prepared (for at most 3 seconds).
98 Actions which take a long time to produce their data can switch this off by
99 setting C<noBusyIndicator> to true, keeping the gui usable while they run:
100  
101 {
102 label => trm('Create Report'),
103 action => 'download',
104 key => 'createReport',
105 noBusyIndicator => true,
106 actionHandler => sub { ... },
107 }
108  
109 =cut
110  
111 0 ▶has actionCfg => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 [];
113 14 };
114  
115 =head2 actionCfgMap
116  
117 Lookup table for action plugins.
118  
119 NOTE: Unique keys are not checked for popup plugins as they don't have
120 action handlers.
121 This allows multiple popup actions using the same plugin instance.
122 In this case an additional cfg parameter C<testingIdPostfix> must be
123 used to make the QoxdooObjectIds unique used from frontend testing.
124  
125 =cut
126  
127 0 ▶has actionCfgMap => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
128 0 my $self = shift;
129 0 my %map;
130 0 for my $row (@{$self->actionCfg}){
131 0 ▶ next unless $row->{action} =~ /^(submit|upload|download|display|autoSubmit|save)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"action"} =~ /^(submit|upload|download|display|autoSubmit|save)/u 0 0 0
132 0 ▶ next unless $row->{key};
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"key"} 0 0 0
133 0 my $key = $row->{key};
134 0 ▶ die mkerror(4646, "Duplicate action key $key") if exists $map{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $map{$key} 0 0 0
135 0 $map{$key} = $row;
136 }
137 0 return \%map;
138 14 };
139  
140  
141 =head1 METHODS
142  
143 All the methods of L<CallBackery::GuiPlugin::Abstract> plus:
144  
145 =cut
146  
147 =head2 massageConfig
148  
149 Function to integrate the plugin configuration recursively into the main config
150 hash.
151  
152 =cut
153  
154 48 ▶sub massageConfig {
Subroutine massageConfig: called CC=7 SCAR=22.8
Pod documented
155 48 my $self = shift;
156 48 my $cfg = shift;
157 48 $self->__fixActionCfg;
158 48 my $actionCfg = $self->actionCfg;
159 48 for my $button (@$actionCfg){
160 72 ▶ if ($button->{action} =~ /popup|wizzard/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($button->{"action"} =~ /popup|wizzard/u) 24 48 72
161 24 my $name = $button->{name};
162 # allow same plugin multiple times
163 24 $button->{name} = $name;
164 24 ▶ if ($cfg->{PLUGIN}{prototype}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->{"PLUGIN"}{"prototype"}{$name}) 0 24 24
165 0 my $newCfg = encode_json($button->{backend});
166 0 my $oldCfg = encode_json($cfg->{PLUGIN}{prototype}{$name}{backend});
167 0 ▶ if ($oldCfg ne 'null' and $newCfg ne $oldCfg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldCfg ne "null" and $newCfg ne $oldCfg) 0 0 0
Condition0%0/3
$oldCfg ne "null" and $newCfg ne $oldCfg
!ll&&!rl&&r
000
MC/DC0%0/2
$oldCfg ne "null" and $newCfg ne $oldCfg
$oldCfg ne "null" $newCfg ne $oldCfg
Truth table0%0/3
A and B
A= $oldCfg ne "null"B= $newCfg ne $oldCfg
ABresult
0X0
100
111
168 0 $self->log->warn("oldCfg=" . dumper $oldCfg);
169 0 $self->log->warn("newCfg=", dumper $newCfg);
170 0 die "Not unique plugin instance name $name not allowed as backend config is different\n";
171 }
172 }
173 my $popup = $cfg->{PLUGIN}{prototype}{$name}
174 24 = $self->app->config->loadAndNewPlugin($button->{backend}{plugin});
175 24 $popup->config($button->{backend}{config});
176 24 $popup->name($name);
177 24 $popup->app($self->app);
178 24 $popup->massageConfig($cfg);
179 }
180 }
181 48 ▶ if (ref $self->user eq 'MockUser') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->user eq "MockUser") 48 0 48
182 # $self->log->debug("massageConfig is done. undefining user");
183 48 $self->user(undef);
184 }
185 48 return;
186 }
187  
188 =head2 __fixActionCfg
189  
190 make sure actionCfg buttons only have keys and no names
191 add properly constructed name properties
192  
193 =cut
194  
195 48 ▶sub __fixActionCfg {
Subroutine __fixActionCfg: called CC=9 SCAR=25.1
196 48 my $self = shift;
197 48 ▶ return $self if $self->{__action_cfg_fixed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__action_cfg_fixed"} 0 48 48
198 48 my $name = $self->name;
199 48 my $pkg = ref $self;
200 48 for my $action (@{$self->actionCfg}) {
201 next if $action->{action} eq 'separator'
202 or $action->{action} eq 'refresh'
203 72 ▶ or $action->{action} eq 'logout';
Branch: 1 branch
BranchTrueFalseTotal
if $action->{"action"} eq "separator" or $action->{"action"} eq "refresh" or $action->{"action"} eq "logout" 0 72 72
Condition33%2/6
$action->{"action"} eq "separator" or $action->{"action"} eq "refresh" or $action->{"action"} eq "logout"
l!l&&r!l&&!r
0072
$action->{"action"} eq "separator" or $action->{"action"} eq "refresh"
l!l&&r!l&&!r
0072
MC/DC0%0/3
$action->{"action"} eq "separator" or $action->{"action"} eq "refresh" or $action->{"action"} eq "logout"
$action->{"action"} eq "separator" $action->{"action"} eq "refresh" $action->{"action"} eq "logout"
Truth table25%1/4
A or B or C
A= $action->{"action"} eq "separator"B= $action->{"action"} eq "refresh"C= $action->{"action"} eq "logout"
ABCresult
1XX1
01X1
0011
0000
204 72 ▶ if ($action->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action->{"name"}) 0 72 72
205 0 $self->log->warn(
206 $pkg . " action should not have a name attribute:"
207 . " name=$action->{name}"
208 );
209 }
210 72 ▶ if (not $action->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action->{"key"}) 0 72 72
211 0 $self->log->warn(
212 $pkg . " action should have a key attribute,"
213 . " created a key from name=$action->{name} instead"
214 );
215 0 $action->{key} = $action->{name};
216 }
217 # popups and wizzards do need a name internally
218 72 ▶ if ($action->{action} =~ /popup|wizzard/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action->{"action"} =~ /popup|wizzard/u) 24 48 72
219 24 $action->{name} = "${name}_$action->{key}";
220 }
221 }
222 48 $self->{__action_cfg_fixed} = 1;
223 48 return $self;
224 }
225  
226  
227 14 1;
228 __END__
« lib/CallBackery/GuiPlugin/Users.pm ↑ Summary blib/lib/CallBackery/GuiPlugin/AbstractCardlist.pm »