lib/Strehler/Element/Role/Configured.pm

filter: Statementstmt 92.5% 100 / 108 Branchbran 68.7% 11 / 16 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 92.3% 36 / 39 Podpod 21.2% 7 / 33 totaltotal 79.8% 166 / 208 CC 14 SCAR 7.1
CC
14
Cov
90%
multilang_data_fields
6.0
allowed_role
3.8
get_schema
2.3
CRAP 2.0
« lib/Strehler/FormFu/Element/Category.pm ↑ Summary blib/lib/Strehler/FormFu/Element/SubmitBlock.pm »
1 package Strehler::Element::Role::Configured;
2 12 $Strehler::Element::Role::Configured::VERSION = '1.6.8';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Dancer2;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Dancer2::Plugin::DBIC;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Lingua::EN::Inflect qw(PL classical);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 requires 'metaclass_data';
10  
11 sub category_accessor
12 26 ▶{
Subroutine category_accessor: called CC=2 SCAR=7.0
Pod documented
13 26 my $self = shift;
14 26 my $category = shift;
15 26 ▶ return undef if ! $category;
Branch: 1 branch
BranchTrueFalseTotal
unless $category 0 26 26
16 26 return $category->can($self->metaclass_data('category_accessor'));
17 }
18  
19 sub item_type
20 813 ▶{
Subroutine item_type: called CC=1 SCAR=0.0
Pod documented
21 813 my $self = shift;
22 813 return $self->metaclass_data('item_type');
23 }
24 sub plural
25 11 ▶{
Subroutine plural: called CC=2 SCAR=7.0
Pod undocumented
26 11 my $self = shift;
27 11 classical(1);
28 11 my $plural = PL($self->item_type());
29 11 ▶ $plural = $plural . 's' if $plural eq $self->item_type();
Branch: 1 branch
BranchTrueFalseTotal
if $plural eq $self->item_type 0 11 11
30 11 return $plural;
31 }
32  
33 sub ORMObj
34 278 ▶{
Subroutine ORMObj: called CC=1 SCAR=0.0
Pod documented
35 278 my $self = shift;
36 278 return $self->metaclass_data('ORMObj');
37 }
38 sub multilang_children
39 158 ▶{
Subroutine multilang_children: called CC=2 SCAR=6.9
Pod documented
40 158 my $self = shift;
41 #Empty string returned instead of undef to avoid error calling can
42 158 ▶ my $children = $self->metaclass_data('multilang_children') || '';
Condition100%2/2
$self->metaclass_data('multilang_children') || ''
l!l
1499
MC/DC100%1/1
$self->metaclass_data('multilang_children') || ''
$self->metaclass_data('multilang_children')
Truth table100%2/2
A
A= $self->metaclass_data('multilang_children')
Aresult
11
00
43 158 return $children;
44 }
45 sub get_schema
46 279 ▶{
Subroutine get_schema: called CC=2 SCAR=8.1
Pod documented
47 279 ▶ if(config->{'Strehler'}->{'schema'})
Branch: 1 branch
BranchTrueFalseTotal
if (config()->{'Strehler'}{'schema'}) { } 0 279 279
48 {
49 0 return schema config->{'Strehler'}->{'schema'};
50 }
51 else
52 {
53 279 return schema;
54 }
55 }
56 sub multilang
57 34 ▶{
Subroutine multilang: called CC=1 SCAR=0.0
Pod documented
58 34 my $self = shift;
59 34 return $self->multilang_children() ne '';
60 }
61 sub _property
62 603 ▶{
Subroutine _property: called CC=2 SCAR=6.9
63 603 my $self = shift;
64 603 my $prop = shift;
65 603 my $default = shift;
66 603 ▶ return exists config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{$prop} ? config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{$prop} : $default;
Branch: 1 branch
BranchTrueFalseTotal
exists config()->{'Strehler'}{'extra_menu'}{$self->item_type}{$prop} ? : 76 527 603
67 }
68 sub visible
69 9 ▶{
Subroutine visible: called CC=1 SCAR=0.0
Pod undocumented
70 9 my $self = shift;
71 9 return $self->_property('visible', 1);
72 }
73 sub auto
74 44 ▶{
Subroutine auto: called CC=1 SCAR=0.0
Pod undocumented
75 44 my $self = shift;
76 44 return $self->_property('auto', 1);
77 }
78 sub exposed
79 21 ▶{
Subroutine exposed: called CC=1 SCAR=0.0
Pod undocumented
80 21 my $self = shift;
81 21 return $self->_property('exposed', 1);
82 }
83 sub slugged
84 13 ▶{
Subroutine slugged: called CC=1 SCAR=0.0
Pod undocumented
85 13 my $self = shift;
86 13 return $self->can('get_by_slug');
87 }
88 sub label
89 0 ▶{
Subroutine label: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $self = shift;
91 0 return $self->_property('label', '???');
92 }
93 sub class
94 0 ▶{
Subroutine class: not called CC=1 SCAR=6.9
Pod undocumented
95 0 my $self = shift;
96 0 return $self->_property('class', 'Strehler::Element');
97 }
98 sub creatable
99 28 ▶{
Subroutine creatable: called CC=1 SCAR=0.0
Pod undocumented
100 28 my $self = shift;
101 28 return $self->_property('creatable', 1);
102 }
103 sub updatable
104 10 ▶{
Subroutine updatable: called CC=1 SCAR=0.0
Pod undocumented
105 10 my $self = shift;
106 10 return $self->_property('updatable', 1);
107 }
108 sub deletable
109 12 ▶{
Subroutine deletable: called CC=1 SCAR=0.0
Pod undocumented
110 12 my $self = shift;
111 12 return $self->_property('deletable', 1);
112 }
113 sub categorized
114 186 ▶{
Subroutine categorized: called CC=1 SCAR=0.0
Pod undocumented
115 186 my $self = shift;
116 186 return $self->_property('categorized', 0);
117 }
118 sub ordered
119 5 ▶{
Subroutine ordered: called CC=1 SCAR=0.0
Pod undocumented
120 5 my $self = shift;
121 5 return $self->_property('ordered', 0);
122 }
123 sub dated
124 5 ▶{
Subroutine dated: called CC=1 SCAR=0.0
Pod undocumented
125 5 my $self = shift;
126 5 return $self->_property('dated', 0);
127 }
128 sub publishable
129 27 ▶{
Subroutine publishable: called CC=1 SCAR=0.0
Pod undocumented
130 27 my $self = shift;
131 27 return $self->_property('publishable', 0);
132 }
133 sub auto_publish
134 22 ▶{
Subroutine auto_publish: called CC=1 SCAR=0.0
Pod undocumented
135 22 my $self = shift;
136 22 return $self->_property('auto_publish', 0);
137 }
138 sub form
139 2 ▶{
Subroutine form: called CC=1 SCAR=0.0
Pod undocumented
140 2 my $self = shift;
141 2 return $self->_property('form', undef);
142 }
143 sub multilang_form
144 2 ▶{
Subroutine multilang_form: called CC=1 SCAR=0.0
Pod undocumented
145 2 my $self = shift;
146 2 return $self->_property('multilang_form', undef);
147 }
148 sub only_default_required
149 27 ▶{
Subroutine only_default_required: called CC=1 SCAR=0.0
Pod undocumented
150 27 my $self = shift;
151 27 return $self->_property('only_default_required', 1);
152 }
153  
154 sub allowed_role
155 9 ▶{
Subroutine allowed_role: called CC=3 SCAR=13.3
Pod undocumented
156 9 my $self = shift;
157 9 ▶ if(exists config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{allowed_role})
Branch: 2 branches
BranchTrueFalseTotal
if (exists config()->{'Strehler'}{'extra_menu'}{$self->item_type}{'allowed_role'}) { } 0 9 9
elsif (exists config()->{'Strehler'}{'extra_menu'}{$self->item_type}{'role'}) { } 0 9 9
158 {
159 0 return config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{allowed_role};
160 }
161 elsif(exists config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{role})
162 {
163 #For retrocompatibility
164 0 return config->{'Strehler'}->{'extra_menu'}->{$self->item_type()}->{role};
165 }
166 else
167 {
168 9 return undef;
169 }
170 }
171 sub custom_list_template
172 9 ▶{
Subroutine custom_list_template: called CC=1 SCAR=0.0
Pod undocumented
173 9 my $self = shift;
174 9 return $self->_property('custom_list_template', undef);
175 }
176 sub add_main_column_span
177 5 ▶{
Subroutine add_main_column_span: called CC=1 SCAR=0.0
Pod undocumented
178 5 my $self = shift;
179 5 return $self->_property('add_main_column_span', 8);
180 }
181 sub custom_snippet_add_position
182 5 ▶{
Subroutine custom_snippet_add_position: called CC=1 SCAR=0.0
Pod undocumented
183 5 my $self = shift;
184 5 return $self->_property('custom_snippet_position', 'left');
185 }
186 sub entity_js
187 5 ▶{
Subroutine entity_js: called CC=1 SCAR=0.0
Pod undocumented
188 5 my $self = shift;
189 5 return $self->_property('entity_js', undef);
190 }
191  
192 sub entity_data
193 9 ▶{
Subroutine entity_data: called CC=2 SCAR=6.9
Pod documented
194 9 my $self = shift;
195 9 my @attributes = ('multilang',
196 'auto',
197 'exposed',
198 'slugged',
199 'label',
200 'class',
201 'creatable',
202 'updatable',
203 'deletable',
204 'categorized',
205 'ordered',
206 'dated',
207 'publishable',
208 'auto_publish',
209 'form',
210 'multilang_form',
211 'only_default_required',
212 'allowed_role',
213 'custom_list_template',
214 'visible',
215 'add_main_column_span',
216 'custom_snippet_add_position',
217 'entity_js');
218 9 my %entity_data;
219 9 foreach my $attr (@attributes)
220 {
221 207 $entity_data{$attr} = $self->$attr();
222 }
223 9 return %entity_data;
224 }
225  
226 sub data_fields
227 39 ▶{
Subroutine data_fields: called CC=1 SCAR=0.0
Pod undocumented
228 39 my $self = shift;
229 39 return $self->get_schema()->resultset($self->ORMObj())->result_source->columns;
230 }
231  
232 sub multilang_data_fields
233 19 ▶{
Subroutine multilang_data_fields: called CC=6 SCAR=17.9
Pod undocumented
234 19 my $self = shift;
235 19 ▶ if($self->multilang())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multilang) { } 16 3 19
236 {
237 16 my @fields = $self->get_schema()->resultset($self->ORMObj())->related_resultset($self->multilang_children())->result_source->columns;
238 16 my @out;
239 16 foreach my $f (@fields)
240 {
241 96 ▶ if($f ne 'id' && $f ne $self->item_type() && $f ne 'language')
Branch: 1 branch
BranchTrueFalseTotal
if ($f ne "id" and $f ne $self->item_type and $f ne "language") 48 48 96
Condition100%6/6
$f ne "id" and $f ne $self->item_type and $f ne "language"
!ll&&!rl&&r
321648
$f ne "id" and $f ne $self->item_type
!ll&&!rl&&r
161664
MC/DC100%3/3
$f ne "id" and $f ne $self->item_type and $f ne "language"
$f ne "id" $f ne $self->item_type $f ne "language"
Truth table100%4/4
A and B and C
A= $f ne "id"B= $f ne $self->item_typeC= $f ne "language"
ABCresult
0XX0
10X0
1100
1111
242 {
243 48 push @out, $f;
244 }
245 }
246 16 return @out;
247 }
248 else
249 {
250 3 return ();
251 }
252 }
253 sub custom_add_snippet
254 0 ▶{
Subroutine custom_add_snippet: not called CC=1 SCAR=6.9
Pod undocumented
255 0 return undef;
256 }
257  
258 =encoding utf8
259  
260 =head1 NAME
261  
262 Strehler::Element::Role::Configured - Configuration role
263  
264 =head1 DESCRIPTION
265  
266 This role is used by Strehler elements to declare their configuration.
267  
268 Every "flag function" just read the role value from Dancer2 config.yml.
269  
270 Creating new entities you can set their flags in config.yml or override Configured role's functions.
271  
272 Overriding functions has priority on config.yml.
273  
274 Slugged attribute is special, it's based on introspection on the class. You can't change it in config.yml and overriding it could be a bad idea.
275  
276 =head1 FUNCTIONS
277  
278 =over 4
279  
280 =item category_accessor
281  
282 arguments: $category
283  
284 retur value: $accessor
285  
286 Return the category accessor used by category module to reference the categorized module.
287  
288 (Value is defined using metaclass_data function)
289  
290 =item item_type
291  
292 retur value: $item_type
293  
294 Return the type of the item
295  
296 (Value is defined using metaclass_data function)
297  
298 =item ORMObj
299  
300 retur value: $ORMObj
301  
302 Return the name of the DBIx::Class Module controlled by the element.
303  
304 (Value is defined using metaclass_data function)
305  
306 =item multilang_children
307  
308 return value: $accessor_name
309  
310 Return the name of the accessor used by DBIX::Class module to reference multilang children rows
311  
312 (Value is defined using metaclass_data function)
313  
314 =item get_schema
315  
316 return $schema
317  
318 Wrapper for Dancer2 schema keyword, used internally to allow developer to use a different schema from default for Strehler
319  
320 =item _property
321  
322 return $prop
323  
324 Generic function to manage flag properties.
325  
326 =item multilang
327  
328 return $bool
329  
330 Considered in entity_data properties, this function says if the element has or has not multilanguage management. Value is deduced by multilang_children attribute.
331  
332 =item "flag functions"
333  
334 =over 6
335  
336 =item *
337  
338 auto
339  
340 =item *
341  
342 exposed
343  
344 =item *
345  
346 label
347  
348 =item *
349  
350 class
351  
352 =item *
353  
354 creatable
355  
356 =item *
357  
358 updatable
359  
360 =item *
361  
362 deletable
363  
364 =item *
365  
366 categorized
367  
368 =item *
369  
370 ordered
371  
372 =item *
373  
374 dated
375  
376 =item *
377  
378 publishable
379  
380 =item *
381  
382 auto_publish
383  
384 =item *
385  
386 form
387  
388 =item *
389  
390 multilang_form
391  
392 =item *
393  
394 allowed_role
395  
396 =item *
397  
398 custom_list_template
399  
400 =item *
401  
402 add_main_column_span
403  
404 =item *
405  
406 custom_snippet_add_position
407  
408 =item *
409  
410 entity_js
411  
412 =back
413  
414 All these functions read from configuration file the property. They can be overriden to configure different values for properties without involving configuration file.
415  
416 For the meaning of every flag see L<Strehler::Manual::ExtraEntityConfiguration>
417  
418 =item "complex info functions"
419  
420 =over 6
421  
422 =item *
423  
424 data_fields
425  
426 =item *
427  
428 multilang_data_fields
429  
430 =item *
431  
432 custom_add_snippet
433  
434 =back
435  
436 All these functions have no reference in the configuration file, but overriding them you can obtain more customization.
437  
438 For the meaning of each function see L<Strehler::Manual::ExtraEntityConfiguration>
439  
440 =item get_schema
441  
442 return $schema
443  
444 Wrapper for Dancer2 schema keyword, used internally to allow developer to use a different schema from default for Strehler
445  
446 =item entity_data
447  
448 return %data
449  
450 Return all the configuration for an element as an hash
451  
452  
453 =back
454  
455 =cut
456  
457  
458  
459  
460 12 1;
« lib/Strehler/FormFu/Element/Category.pm ↑ Summary blib/lib/Strehler/FormFu/Element/SubmitBlock.pm »