BootstrapHelpers/Helpers.pm

filter: Statementstmt 78.4% 396 / 505 Branchbran 46.5% 109 / 234 Conditioncond 49.0% 27 / 55 MC/DCmcdc 14.7% 5 / 34 Subroutinesub 85.7% 54 / 63 Podpod 0.0% 0 / 44 totaltotal 63.2% 591 / 935 CC 146 SCAR 23.5
CC
146
Cov
67%
make_navbar_form
42.0
make_nav_meat
24.5
fix_input_ender
24.1
CRAP 10.5
↑ Summary BootstrapHelpers.pm »
1 16 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Mojolicious::Plugin::BootstrapHelpers::Helpers;
5  
6 # ABSTRACT: Supporting module
7 16 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
8 16 our $VERSION = '0.0206';
9  
10 16 ▶use List::Util qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Mojo::ByteStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Mojo::Util 'xml_escape';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use String::Trim;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use String::Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use experimental qw/postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶sub bootstraps_bootstraps {
Subroutine bootstraps_bootstraps: called CC=7 SCAR=27.2
Pod undocumented
19 1 my $c = shift;
20 1 my $arg = shift;
21  
22 1 my $bs_version = '3.4.1';
23  
24 1 my $css = qq{<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/$bs_version/css/bootstrap.min.css">};
25 1 my $theme = qq{<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/$bs_version/css/bootstrap-theme.min.css">};
26 1 my $js = qq{<script src="https://maxcdn.bootstrapcdn.com/bootstrap/$bs_version/js/bootstrap.min.js"></script>};
27 1 my $jq = q{<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>};
28  
29 1 ▶ return out(
Branch: 6 branches
BranchTrueFalseTotal
!defined($arg) ? : 1 0 1
$arg eq 'css' ? : 0 0 0
$arg eq 'js' ? : 0 0 0
$arg eq 'jsq' ? : 0 0 0
$arg eq 'all' ? : 0 0 0
$arg eq 'allq' ? : 0 0 0
30 !defined $arg ? $css
31 : $arg eq 'css' ? join "\n" => $css, $theme
32 : $arg eq 'js' ? join "\n" => $js
33 : $arg eq 'jsq' ? join "\n" => $jq, $js
34 : $arg eq 'all' ? join "\n" => $css, $theme, $js
35 : $arg eq 'allq' ? join "\n" => $css, $theme, $jq, $js
36 : ''
37 );
38 }
39  
40 1 ▶sub bootstrap_panel {
Subroutine bootstrap_panel: called CC=1 SCAR=0.0
Pod undocumented
41 1 my($c, $title, $callback, $content, $attr) = parse_call(@_);
42  
43 1 $attr = add_classes($attr, 'panel', { panel => 'panel-%s', panel_default => 'default'});
44  
45 1 my $body = qq{
46 <div class="panel-body">
47 } . contents($callback, $content) . qq{
48 </div>
49 };
50  
51 1 return create_panel($c, $title, $body, $attr);
52  
53 }
54 #-header => [buttongroup => ['Scan', ['#'], data => { bind => 'click: scanDatabases'}]]
55 1 ▶sub create_panel {
Subroutine create_panel: called CC=6 SCAR=21.2
Pod undocumented
56 1 my $c = shift;
57 1 my $title = shift;
58 1 my $body = shift;
59 1 my $attr = shift;
60  
61 1 ▶ my $header_attr = exists $attr->{'-header'} ? delete($attr->{'-header'}) : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'-header'} ? : 0 1 1
62 1 my $header_button_groups = '';
63 1 ▶ if(scalar keys @$header_attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys @$header_attr) 0 1 1
64 0 for my $attr (shift @$header_attr) {
65 0 ▶ if($attr eq 'buttongroup') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq "buttongroup") 0 0 0
66 0 $header_button_groups .= bootstrap_buttongroup($c, class => 'pull-right', (shift @$header_attr)->@*);
67 }
68 }
69 }
70  
71 1 ▶ my $tag = qq{
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 0 1 1
72 <div class="$attr->{'class'}">
73 } . (defined $title ? qq{
74 <div class="panel-heading">
75 <h3 class="panel-title">$header_button_groups$title</h3>
76 </div>
77 } : '') . qq{
78 $body
79 </div>
80 };
81  
82 1 return out($tag);
83 }
84  
85 1 ▶sub bootstrap_table {
Subroutine bootstrap_table: called CC=5 SCAR=17.1
Pod undocumented
86 1 my $c = shift;
87 1 ▶ my $callback = ref $_[-1] eq 'CODE' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'CODE' ? : 1 0 1
88 1 ▶ my $title = scalar @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ % 2 ? : 0 1 1
89 1 my $attr = parse_attributes(@_);
90  
91 1 $attr = add_classes($attr, 'table', { table => 'table-%s' });
92 1 my $html = htmlify_attrs($attr);
93  
94 1 my $table = qq{
95 <table class="$attr->{'class'}"$html>
96 } . $callback->() . qq{
97 </table>
98 };
99  
100 1 ▶ if(defined $title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $title) 0 1 1
101 0 $attr->{'panel'} = add_classes($attr->{'panel'}, 'panel', { panel => 'panel-%s', panel_default => 'default'});
102 }
103  
104 1 ▶ return defined $title ? create_panel($c, $title, $table, $attr->{'panel'}) : out($table);
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 0 1 1
105 }
106  
107 44 ▶sub htmlify_attrs {
Subroutine htmlify_attrs: called CC=3 SCAR=11.4
Pod undocumented
108 44 my $attr = shift;
109 44 ▶ return '' if !defined $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr 0 44 44
110 44 $attr = cleanup_attrs({$attr->%*}); #* Make a copy
111  
112 44 my $html = join ' ' => map { qq{$_="$attr->{ $_ }"} } grep { length $attr->{ $_ } } sort keys $attr->%*;
113 44 ▶ return ' ' . $html if defined $html;
Branch: 1 branch
BranchTrueFalseTotal
if defined $html 44 0 44
114 0 return '';
115 }
116  
117 1 ▶sub bootstrap_formgroup {
Subroutine bootstrap_formgroup: called CC=5 SCAR=16.6
Pod undocumented
118 1 my $c = shift;
119 1 ▶ my $title = ref $_[-1] eq 'CODE' ? pop
Branch: 2 branches
BranchTrueFalseTotal
ref $_[-1] eq 'CODE' ? : 0 1 1
scalar @_ % 2 ? : 1 0 1
120 : scalar @_ % 2 ? shift
121 : undef;
122 1 my $attr = parse_attributes(@_);
123  
124 1 ▶ $attr->{'column_information'} = delete $attr->{'cols'} if ref $attr->{'cols'} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr->{"cols"} eq "HASH" 0 1 1
125  
126 1 my($id, $input) = fix_input($c, $attr);
127 1 ▶ my $label = defined $title ? fix_label($c, $id, $title, $attr) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 1 0 1
128  
129 1 $attr = add_classes($attr, 'form-group', { size => 'form-group-%s'});
130 1 $attr = cleanup_attrs($attr);
131  
132  
133 1 my $tag = qq{
134 <div class="$attr->{'class'}">
135 $label
136 $input
137 </div>
138 };
139  
140 1 return out($tag);
141 }
142  
143 11 ▶sub bootstrap_button {
Subroutine bootstrap_button: called CC=12 SCAR=29.2
Pod undocumented
144 11 my $c = shift;
145 11 ▶ my $content = ref $_[-1] eq 'CODE' ? pop : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'CODE' ? : 0 11 11
146 11 ▶ $content = '' if !defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 11 11
147  
148 11 ▶ my @url = shift->@* if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 11 11
149 11 my $attr = parse_attributes(@_);
150  
151 11 ▶ my $caret = exists $attr->{'__caret'} && $attr->{'__caret'} ? (length $content ? ' ' : '') . q{<span class="caret"></span>} : '';
Branch: 2 branches
BranchTrueFalseTotal
exists $attr->{'__caret'} && $attr->{'__caret'} ? : 0 11 11
length $content ? : 0 0 0
Condition33%1/3
exists $attr->{"__caret"} and $attr->{"__caret"}
!ll&&!rl&&r
1100
MC/DC0%0/2
exists $attr->{"__caret"} and $attr->{"__caret"}
exists $attr->{"__caret"} $attr->{"__caret"}
Truth table33%1/3
A and B
A= exists $attr->{"__caret"}B= $attr->{"__caret"}
ABresult
0X0
100
111
152  
153 11 ▶ $attr->{'type'} = 'button' if !scalar @url && !exists $attr->{'type'};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @url or exists $attr->{"type"} 10 1 11
Condition66%2/3
scalar @url or exists $attr->{"type"}
l!l&&r!l&&!r
0110
MC/DC50%1/2
scalar @url or exists $attr->{"type"}
scalar @url exists $attr->{"type"}
Truth table66%2/3
A or B
A= scalar @urlB= exists $attr->{"type"}
ABresult
1X1
011
000
154 11 $attr = add_classes($attr, 'btn', { size => 'btn-%s', button => 'btn-%s', button_default => 'default' });
155 11 ▶ $attr = add_classes($attr, 'active') if $attr->{'__active'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"__active"} 0 11 11
156 11 ▶ $attr = add_classes($attr, 'block') if $attr->{'__block'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"__block"} 0 11 11
157 11 $attr = add_disabled($attr, scalar @url);
158 11 $attr = cleanup_attrs($attr);
159  
160 # We have an url
161 11 ▶ if(scalar @url) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @url) { } 0 11 11
162 0 $attr->{'href'} = url_for($c, \@url);
163  
164 0 my $html = htmlify_attrs($attr);
165 0 return out(qq{<a$html>} . content_single($content) . qq{$caret</a>});
166 }
167 else {
168 11 my $html = htmlify_attrs($attr);
169 11 return out(qq{<button$html>} . content_single($content) . qq{$caret</button>});
170 }
171  
172 }
173  
174 0 ▶sub bootstrap_submit {
Subroutine bootstrap_submit: not called CC=1 SCAR=6.9
Pod undocumented
175 0 push @_ => (type => 'submit');
176 0 return bootstrap_button(@_);
177 }
178  
179 1 ▶sub bootstrap_context_menu {
Subroutine bootstrap_context_menu: called CC=1 SCAR=0.0
Pod undocumented
180 1 my $c = shift;
181 1 my %args = @_;
182 1 my $items = delete $args{'items'};
183 1 my $list = make_dropdown_list($c, \%args, $items);
184  
185 1 return out($list);
186 }
187  
188 1 ▶sub bootstrap_dropdown {
Subroutine bootstrap_dropdown: called CC=1 SCAR=0.0
Pod undocumented
189 1 my $meat = make_dropdown_meat(shift, shift->@*);
190  
191 1 my $dropdown = qq{
192 <div class="dropdown">
193 $meat
194 </div>
195 };
196 1 return out($dropdown);
197 }
198  
199 1 ▶sub make_dropdown_meat {
Subroutine make_dropdown_meat: called CC=4 SCAR=14.0
Pod undocumented
200 1 my $c = shift;
201  
202 1 my $button_text = shift;
203 1 ▶ my @url = ref $_[0] eq 'ARRAY' ? shift->@* : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 1 1
204 1 my $attr = parse_attributes(@_);
205  
206 1 ▶ my $items = delete $attr->{'items'} || [];
Condition50%1/2
delete $attr->{'items'} || []
l!l
10
MC/DC0%0/1
delete $attr->{'items'} || []
delete $attr->{'items'}
Truth table50%1/2
A
A= delete $attr->{'items'}
Aresult
11
00
207 1 ▶ my $ulattr = { __right => exists $attr->{'__right'} ? delete $attr->{'__right'} : 0 };
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'__right'} ? : 1 0 1
208 1 my $listhtml = make_dropdown_list($c, $ulattr, $items);
209  
210 1 $attr = add_classes($attr, 'dropdown-toggle');
211 1 $attr->{'data-toggle'} = 'dropdown';
212 1 $attr->{'type'} = 'button';
213 1 my $button = bootstrap_button($c, $button_text, @url, $attr->%*);
214  
215 1 my $out = qq{
216 $button
217 $listhtml
218 };
219 1 return out($out);
220 }
221  
222 2 ▶sub make_dropdown_list {
Subroutine make_dropdown_list: called CC=6 SCAR=18.0
Pod undocumented
223 2 my $c = shift;
224 2 my $attr = shift;
225 2 my $items = shift;
226  
227 2 $attr = add_classes($attr, 'dropdown-menu');
228 2 ▶ $attr = add_classes($attr, 'dropdown-menu-right') if $attr->{'__right'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"__right"} 1 1 2
229 2 my $attrhtml = htmlify_attrs($attr);
230 2 my $menuitems = '';
231  
232 ITEM:
233 2 foreach my $item ($items->@*) {
234 8 ▶ if(ref $item eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq "") 0 8 8
235 0 $menuitems .= qq{<li class="dropdown-header">$item</li>};
236 }
237 8 ▶ next ITEM if ref $item ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $item ne "ARRAY" 0 8 8
238 8 ▶ if(!scalar $item->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @$item) { } 2 6 8
239 2 $menuitems .= q{<li class="divider"></li>} ;
240 }
241 else {
242 6 $menuitems .= create_dropdown_menuitem($c, $item->@*);
243 }
244  
245 }
246 2 my $out = qq{
247 <ul$attrhtml>
248 $menuitems
249 </ul>
250 };
251 2 return out($out);
252 }
253  
254 6 ▶sub create_dropdown_menuitem {
Subroutine create_dropdown_menuitem: called CC=4 SCAR=14.0
Pod undocumented
255 6 my $c = shift;
256 6 ▶ my $item_text = iscoderef($_[-1]) ? pop : shift;
Branch: 1 branch
BranchTrueFalseTotal
iscoderef($_[-1]) ? : 0 6 6
257 6 my @url = shift->@*;
258  
259 6 my $attr = parse_attributes(@_);
260 6 $attr = add_classes($attr, 'menuitem');
261 6 ▶ my $liattr = { __disabled => exists $attr->{'__disabled'} ? delete $attr->{'__disabled'} : 0 };
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'__disabled'} ? : 0 6 6
262 6 $liattr = add_disabled($liattr, 1);
263 6 ▶ $attr->{'tabindex'} ||= -1;
Condition50%1/2
$attr->{"tabindex"} ||= -1
l!l
06
MC/DC0%0/1
$attr->{"tabindex"} ||= -1
$attr->{"tabindex"}
Truth table50%1/2
A
A= $attr->{"tabindex"}
Aresult
11
00
264 6 $attr->{'href'} = url_for($c, \@url);
265  
266 6 my $html = htmlify_attrs($attr);
267 6 my $lihtml = htmlify_attrs($liattr);
268  
269 6 my $tag = qq{<li$lihtml><a$html>$item_text</a></li>};
270  
271 6 return out($tag);
272 }
273  
274 3 ▶sub bootstrap_buttongroup {
Subroutine bootstrap_buttongroup: called CC=2 SCAR=8.1
Pod undocumented
275 3 my $c = shift;
276  
277 #* Shortcut for one button menus
278 3 ▶ if(ref $_[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "ARRAY") 0 3 3
279 0 my $meat = make_dropdown_meat($c, $_[0]->@*);
280 0 my $menu = qq{<div class="btn-group">$meat</div>};
281 0 return out($menu);
282 }
283 3 my($buttons, $html) = make_buttongroup_meat($c, @_);
284  
285 3 my $tag = qq{
286 <div$html>
287 $buttons
288 </div>};
289  
290 3 return out($tag);
291 }
292  
293 3 ▶sub make_buttongroup_meat {
Subroutine make_buttongroup_meat: called CC=12 SCAR=29.9
Pod undocumented
294 3 my $c = shift;
295  
296 3 my $attr = parse_attributes(@_);
297 3 my $buttons_info = delete $attr->{'buttons'};
298  
299 3 ▶ my $button_group_class = delete $attr->{'__vertical'} ? 'btn-group-vertical' : 'btn-group';
Branch: 1 branch
BranchTrueFalseTotal
delete $attr->{'__vertical'} ? : 0 3 3
300 3 ▶ my $justified_class = delete $attr->{'__justified'} ? 'btn-group-justified' : ();
Branch: 1 branch
BranchTrueFalseTotal
delete $attr->{'__justified'} ? : 0 3 3
301  
302 3 $attr = add_classes($attr, { size => 'btn-group-%s' });
303  
304 #* For the possible inner btn-group, use the same base classes (except justified/vertical/pull-right).
305 #* We add possible .dropup in the loop
306 3 my $inner_attr = add_classes({ class => $attr->{'class'} }, 'btn-group');
307 3 $inner_attr->{'class'} =~ s{\bpull-right\b}{};
308  
309 #* These must come after the inner button group has been given the classes.
310 3 $attr = add_classes($attr, $button_group_class, $justified_class);
311 3 my $html = htmlify_attrs($attr);
312  
313  
314 3 my $buttons = '';
315  
316 BUTTON:
317 3 foreach my $button ($buttons_info->@*) {
318 9 ▶ next BUTTON if ref $button ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $button ne "ARRAY" 0 9 9
319  
320 9 my $button_text = shift $button->@*;
321 9 ▶ my @url = ref $button->[0] eq 'ARRAY' ? shift $button->@* : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $button->[0] eq 'ARRAY' ? : 0 9 9
322 9 my $button_attr = parse_attributes($button->@*);
323 9 ▶ my $items = delete $button_attr->{'items'} || [];
Condition50%1/2
delete $button_attr->{'items'} || []
l!l
09
MC/DC0%0/1
delete $button_attr->{'items'} || []
delete $button_attr->{'items'}
Truth table50%1/2
A
A= delete $button_attr->{'items'}
Aresult
11
00
324  
325 9 ▶ if(!scalar $items->@*) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$items) 9 0 9
326 9 my $bootstrap_button = bootstrap_button($c, $button_text, @url, $button_attr->%*);
327  
328 #* Justified + No url -> button -> must nest
329 9 ▶ if(length $justified_class && !scalar @url) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $justified_class and not scalar @url) { } 0 9 9
Condition33%1/3
length $justified_class and not scalar @url
!ll&&!rl&&r
900
MC/DC0%0/2
length $justified_class and not scalar @url
length $justified_class not scalar @url
Truth table33%1/3
A and not(B)
A= length $justified_classB= not scalar @url
ABresult
0X0
100
111
330 0 $buttons .= qq{<div class="btn-group">$bootstrap_button</div>};
331 }
332 else {
333 9 $buttons .= $bootstrap_button;
334 }
335 9 next BUTTON;
336 }
337  
338 0 ▶ my $dropup_class = delete $button_attr->{'__dropup'} ? 'dropup' : ();
Branch: 1 branch
BranchTrueFalseTotal
delete $button_attr->{'__dropup'} ? : 0 0 0
339 0 $inner_attr = add_classes($inner_attr, $dropup_class);
340 0 my $inner_html = htmlify_attrs($inner_attr);
341 0 ▶ my $meat = make_dropdown_meat($c, $button_text, (scalar @url ? \@url : ()), $button_attr->%*, items => $items);
Branch: 1 branch
BranchTrueFalseTotal
scalar @url ? : 0 0 0
342 0 $buttons .= qq{
343 <div$inner_html>
344 $meat
345 </div>
346 };
347  
348 }
349 3 return ($buttons, $html);
350 }
351  
352 1 ▶sub bootstrap_toolbar {
Subroutine bootstrap_toolbar: called CC=2 SCAR=6.9
Pod undocumented
353 1 my $c = shift;
354  
355 1 my $attr = parse_attributes(@_);
356 1 my $groups = delete $attr->{'groups'};
357  
358 1 $attr = add_classes($attr, 'btn-toolbar');
359 1 my $html = htmlify_attrs($attr);
360  
361 1 my $toolbar = '';
362 1 foreach my $group ($groups->@*) {
363 2 $toolbar .= bootstrap_buttongroup($c, $group->%*);
364 }
365  
366 1 my $tag = qq{
367 <div$html>
368 $toolbar
369 </div>
370 };
371  
372 1 return out($tag);
373 }
374  
375 1 ▶sub bootstrap_navbar {
Subroutine bootstrap_navbar: called CC=12 SCAR=27.4
Pod undocumented
376 1 my $c = shift;
377  
378 1 my($possible_toggler_id, $navbar_header) = ();
379  
380 1 my $content_html = '';
381 1 my $has_inverse = 0;
382 1 my $container = 'fluid';
383  
384 1 ▶ while(scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 1 1 2
385 1 my $key = shift;
386 1 my @arguments = ($c, shift);
387  
388 1 ▶ $content_html .= $key eq 'nav' ? make_navbar_nav(@arguments)
Branch: 4 branches
BranchTrueFalseTotal
$key eq 'nav' ? : 0 1 1
$key eq 'form' ? : 0 1 1
$key eq 'button' ? : 0 1 1
$key eq 'p' ? : 0 1 1
389 : $key eq 'form' ? make_navbar_form(@arguments)
390 : $key eq 'button' ? make_navbar_button(@arguments)
391 : $key eq 'p' ? make_navbar_p(@arguments)
392 : ''
393 ;
394 1 ▶ if($key eq 'header') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "header") 1 0 1
395 1 ($possible_toggler_id, $navbar_header) = make_navbar_header(@arguments);
396 }
397 1 ▶ if($key eq '__inverse') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "__inverse") 0 1 1
398 0 $has_inverse = 1;
399 }
400 1 ▶ if($key eq 'container') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "container") 0 1 1
401 0 $container = $arguments[1];
402 }
403  
404 }
405 1 ▶ $container = $container eq 'normal' ? 'container' : 'container-fluid';
Branch: 1 branch
BranchTrueFalseTotal
$container eq 'normal' ? : 0 1 1
406  
407 1 ▶ my $attr = $has_inverse ? { __inverse => 1 } : {};
Branch: 1 branch
BranchTrueFalseTotal
$has_inverse ? : 0 1 1
408 1 $attr = add_classes($attr, 'navbar', { navbar => 'navbar-%s', navbar_default => 'default' });
409 1 my $html = htmlify_attrs($attr);
410 1 ▶ if(length $content_html) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $content_html) 0 1 1
411 0 $content_html = qq{
412 <div class="collapse navbar-collapse" id="$possible_toggler_id">
413 $content_html
414 </div>
415 };
416 }
417  
418 1 my $tag = qq{
419 <nav$html>
420 <div class="$container">
421 $navbar_header
422 $content_html
423 </div>
424 </nav>
425 };
426  
427 1 return out($tag);
428  
429 }
430 1 ▶sub make_navbar_header {
Subroutine make_navbar_header: called CC=6 SCAR=18.6
Pod undocumented
431 1 my($c, $header, $html_header) = @_;
432  
433 1 ▶ return (undef, $html_header) if $html_header;
Branch: 1 branch
BranchTrueFalseTotal
if $html_header 0 1 1
434  
435 1 my $brand = shift $header->@*;
436 1 ▶ my $url = url_for($c, shift $header->@* || []);
Condition50%1/2
shift @$header || []
l!l
10
MC/DC0%0/1
shift @$header || []
shift @$header
Truth table50%1/2
A
A= shift @$header
Aresult
11
00
437 1 my $header_attr = parse_attributes($header->@*);
438 1 ▶ my $toggler_id = delete $header_attr->{'toggler'} || 'collapsable-' . String::Random->new->randregex('[a-z]{20}');
Condition50%1/2
delete $header_attr->{'toggler'} || 'collapsable-' . 'String::Random'->new->randregex('[a-z]{20}')
l!l
10
MC/DC0%0/1
delete $header_attr->{'toggler'} || 'collapsable-' . 'String::Random'->new->randregex('[a-z]{20}')
delete $header_attr->{'toggler'}
Truth table50%1/2
A
A= delete $header_attr->{'toggler'}
Aresult
11
00
439 1 my $has_hamburger = delete $header_attr->{'__hamburger'};
440 1 ▶ my $hamburger = $has_hamburger ? get_hamburger($toggler_id) : '';
Branch: 1 branch
BranchTrueFalseTotal
$has_hamburger ? : 1 0 1
441 1 $header_attr = add_classes($header_attr, 'navbar-brand');
442  
443 1 ▶ my $brand_html = defined $brand ? qq{<a class="navbar-brand" href="$url">$brand</a>} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $brand ? : 1 0 1
444  
445 1 my $navbar_header = qq{
446 <div class="navbar-header">
447 $hamburger
448 $brand_html
449 </div>
450 };
451  
452 1 return ($toggler_id, $navbar_header);
453  
454 }
455  
456 0 ▶sub make_navbar_nav {
Subroutine make_navbar_nav: not called CC=1 SCAR=6.9
Pod undocumented
457 0 my $c = shift;
458 0 my $nav = shift;
459  
460 0 my $attr = parse_attributes($nav->@*);
461 0 my $items = delete $attr->{'items'};
462 0 $attr = add_classes($attr, 'nav', 'navbar-nav', { direction => 'navbar-%s' });
463 0 my $html = htmlify_attrs($attr);
464  
465 0 my $tag = "<ul$html>";
466 0 $tag .= make_nav_meat($c, $items);
467  
468 0 $tag .= '</ul>';
469 0 return $tag;
470 }
471  
472 0 ▶sub make_navbar_form {
Subroutine make_navbar_form: not called CC=6 SCAR=37.4
Pod undocumented
473 0 my $c = shift;
474 0 my $form = shift;
475 0 my $args = shift $form->@*;
476 0 my $contents = shift $form->@*;
477 0 my $url = shift $args->@*;
478  
479 0 my $attr = parse_attributes($args->@*);
480  
481 0 $attr = add_classes($attr, 'navbar-form', { direction => 'navbar-%s', direction_default => 'left' });
482 0 $attr = cleanup_attrs($attr);
483  
484 0 my $tag = '';
485 0 ▶ for (my $index = 0; $index < scalar $contents->@*; $index += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < scalar @$contents) 0 0 0
486 0 my $key = $contents->[$index];
487 0 my @arguments = ($c, $contents->[$index + 1]->@*);
488  
489 0 ▶ if($key eq 'formgroup') {
Branch: 4 branches
BranchTrueFalseTotal
if ($key eq 'formgroup') { } 0 0 0
elsif ($key eq 'submit_button') { } 0 0 0
elsif ($key eq 'button') { } 0 0 0
elsif ($key eq 'input') { } 0 0 0
490 0 $tag .= bootstrap_formgroup(@arguments);
491 }
492 elsif($key eq 'submit_button') {
493 0 $tag .= bootstrap_submit(@arguments);
494 }
495 elsif($key eq 'button') {
496 0 $tag .= bootstrap_button(@arguments)
497 }
498 elsif($key eq 'input') {
499 0 $tag .= bootstrap_input(@arguments);
500 }
501 }
502  
503 0 ▶ $tag = Mojolicious::Plugin::TagHelpers::_form_for($c, $url->@*, $attr->%*, sub { $tag });
Subroutine __ANON__: not called CC=1 SCAR=6.9
504 0 return out($tag);
505  
506 }
507  
508 0 ▶sub make_navbar_button($c, $arg) {
Subroutine make_navbar_button: not called CC=1 SCAR=6.9
Pod undocumented
509 0 my $text = shift $arg->@*;
510 0 my $url = shift $arg->@*;
511 0 my $attr = parse_attributes($arg->@*);
512 0 $attr = add_classes($attr, 'navbar-btn', { direction => 'navbar-%s' });
513 0 return bootstrap_button($c, $text, $url, $attr->%*);
514 }
515  
516 0 ▶sub make_navbar_p($c, $arg) {
Subroutine make_navbar_p: not called CC=1 SCAR=6.9
Pod undocumented
517 0 my $text = shift $arg->@*;
518 0 my $attr = parse_attributes($arg->@*);
519 0 $attr = add_classes($attr, 'navbar-text', { direction => 'navbar-%s' });
520 0 my $html = htmlify_attrs($attr);
521  
522 0 return out(qq{<p$html>$text</p>});
523 }
524  
525 1 ▶sub get_hamburger {
Subroutine get_hamburger: called CC=1 SCAR=0.0
Pod undocumented
526 1 my $toggler_id = shift;
527  
528 1 my $tag = qq{
529 <button class="collapsed navbar-toggle" data-target="#$toggler_id" data-toggle="collapse" type="button">
530 <span class="icon-bar"></span>
531 <span class="icon-bar"></span>
532 <span class="icon-bar"></span>
533 </button>
534 };
535 1 return $tag;
536 }
537  
538 1 ▶sub make_nav_meat {
Subroutine make_nav_meat: called CC=11 SCAR=32.0
Pod undocumented
539 1 my $c = shift;
540 1 my $contents = shift;
541  
542 1 my $tag = '';
543 CONTENT:
544 1 foreach my $content ($contents->@*) {
545 4 ▶ next CONTENT if ref $content ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $content ne "ARRAY" 0 4 4
546  
547 4 my $text = shift $content->@*;
548 4 my $url = url_for($c, shift $content->@*);
549 4 my $attr = parse_attributes($content->@*);
550  
551 4 ▶ my $items = delete $attr->{'items'} || [];
Condition50%1/2
delete $attr->{'items'} || []
l!l
04
MC/DC0%0/1
delete $attr->{'items'} || []
delete $attr->{'items'}
Truth table50%1/2
A
A= delete $attr->{'items'}
Aresult
11
00
552 #* No sub menu
553 4 ▶ if(!scalar $items->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @$items) { } 4 0 4
554 4 my $active = delete $attr->{'__active'};
555 4 my $disabled = delete $attr->{'__disabled'};
556 4 ▶ my $li_attr = exists $attr->{'-li'} ? parse_attributes(delete($attr->{'-li'})->@*) : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'-li'} ? : 0 4 4
557 4 ▶ $li_attr = add_classes($li_attr, $active ? 'active' : (), $disabled ? 'disabled' : ());
Branch: 2 branches
BranchTrueFalseTotal
$active ? : 1 3 4
$disabled ? : 1 3 4
558 4 my $li_html = htmlify_attrs($li_attr);
559  
560 4 my $a_attr = htmlify_attrs($attr);
561  
562 4 my $link_html = qq{<a href="$url"$a_attr>$text</a>};
563 4 $tag .= qq{<li$li_html>$link_html</li>};
564 4 next CONTENT;
565 }
566 else {
567 0 $attr = add_classes($attr, 'dropdown-toggle');
568 0 $attr->{'data-toggle'} = 'dropdown';
569 0 $attr->{'href'} = $url;
570 0 ▶ my $caret = delete $attr->{'__caret'} ? ' <span class="caret"></span>' : '';
Branch: 1 branch
BranchTrueFalseTotal
delete $attr->{'__caret'} ? : 0 0 0
571 0 my $button_arg = htmlify_attrs($attr);
572 0 my $button_html = qq{<a$button_arg>$text$caret</a>};
573  
574 0 my $lis = '';
575 ITEM:
576 0 foreach my $item ($items->@*) {
577 0 ▶ if(!scalar $item->@*) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$item) 0 0 0
578 0 $lis .= q{<li class="divider"></li>};
579 0 next ITEM;
580 }
581 0 my $text = shift $item->@*;
582 0 my $url = url_for($c, shift $item->@*);
583 0 my $a_attr = parse_attributes($item->@*);
584 0 $a_attr->{'href'} = $url;
585 0 my $a_html = htmlify_attrs($a_attr);
586 0 $lis .= qq{<li><a$a_html>$text</a></li>};
587 }
588 0 $tag .= qq{
589 <li class="dropdown">
590 $button_html
591 <ul class="dropdown-menu">
592 $lis
593 </ul>
594 </li>
595 };
596 }
597 }
598 1 return $tag;
599 }
600  
601 1 ▶sub bootstrap_nav {
Subroutine bootstrap_nav: called CC=5 SCAR=17.2
Pod undocumented
602 1 my $c = shift;
603 1 my $attr = parse_attributes(@_);
604 1 my $pills = delete $attr->{'pills'};
605 1 my $tabs = delete $attr->{'tabs'};
606  
607 1 ▶ my $which = $pills ? 'nav-pills'
Branch: 2 branches
BranchTrueFalseTotal
$pills ? : 1 0 1
$tabs ? : 0 0 0
608 : $tabs ? 'nav-tabs'
609 : ()
610 ;
611 1 ▶ my $justified = delete $attr->{'__justified'} ? 'nav-justified' : ();
Branch: 1 branch
BranchTrueFalseTotal
delete $attr->{'__justified'} ? : 0 1 1
612 1 $attr = add_classes($attr, 'nav', $which, $justified);
613 1 my $html = htmlify_attrs($attr);
614 1 ▶ my $either = $pills || $tabs;
Condition33%1/3
$pills || $tabs
l!l&&r!l&&!r
100
MC/DC0%0/2
$pills || $tabs
$pills $tabs
Truth table33%1/3
A || B
A= $pillsB= $tabs
ABresult
1X1
011
000
615  
616 1 my $tag = make_nav_meat($c, $either);
617 1 $tag = qq{<ul$html>$tag</ul>};
618  
619 1 return out($tag);
620 }
621  
622 1 ▶sub bootstrap_badge {
Subroutine bootstrap_badge: called CC=4 SCAR=14.8
Pod undocumented
623 1 my $c = shift;
624 1 ▶ my $content = iscoderef($_[-1]) ? pop : shift;
Branch: 1 branch
BranchTrueFalseTotal
iscoderef($_[-1]) ? : 0 1 1
625 1 my $attr = parse_attributes(@_);
626  
627 1 $attr = add_classes($attr, 'badge', { direction => 'pull-%s' });
628 1 my $html = htmlify_attrs($attr);
629  
630 1 ▶ my $badge = defined $content && length $content ? qq{<span$html>$content</span>} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $content && length $content ? : 1 0 1
Condition33%1/3
defined $content and length $content
!ll&&!rl&&r
001
MC/DC0%0/2
defined $content and length $content
defined $content length $content
Truth table33%1/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
631  
632 1 return out($badge);
633 }
634  
635 2 ▶sub bootstrap_icon {
Subroutine bootstrap_icon: called CC=3 SCAR=11.2
Pod undocumented
636 2 my $c = shift;
637 2 my $icon = shift;
638  
639 2 my $icon_class = $c->config->{'Plugin::BootstrapHelpers'}{'icons'}{'class'};
640 2 my $formatter = $c->config->{'Plugin::BootstrapHelpers'}{'icons'}{'formatter'};
641  
642 2 my $this_icon = sprintf $formatter => $icon;
643 2 my $attr = parse_attributes(@_);
644 2 $attr = add_classes($attr, $icon_class, $this_icon);
645 2 my $html = htmlify_attrs($attr);
646  
647 2 ▶ return '' if !defined $icon || !length $icon;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $icon and length $icon 0 2 2
Condition33%1/3
defined $icon and length $icon
!ll&&!rl&&r
002
MC/DC0%0/2
defined $icon and length $icon
defined $icon length $icon
Truth table33%1/3
A and B
A= defined $iconB= length $icon
ABresult
0X0
100
111
648 2 return out(qq{<span$html></span>});
649 }
650  
651 1 ▶sub bootstrap_input {
Subroutine bootstrap_input: called CC=5 SCAR=16.7
Pod undocumented
652 1 my $c = shift;
653 1 my $attr = parse_attributes(@_);
654  
655 1 my $prepend = delete $attr->{'prepend'};
656 1 my $append = delete $attr->{'append'};
657  
658 1 my(undef, $input_tag) = fix_input($c, (delete $attr->{'input'}) );
659 1 $attr = add_classes($attr, 'input-group', { size => 'input-group-%s' });
660 1 my $html = htmlify_attrs($attr);
661  
662 1 my($prepend_tag, $append_tag) = undef;
663  
664 1 ▶ if($prepend) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prepend) 1 0 1
665 1 $prepend_tag = fix_input_ender($c, $prepend);
666 }
667 1 ▶ if($append) {
Branch: 1 branch
BranchTrueFalseTotal
if ($append) 0 1 1
668 0 $append_tag = fix_input_ender($c, $append);
669 }
670  
671 1 ▶ my $tag = qq{
Condition50%2/4
$prepend_tag || ''
l!l
10
$append_tag || ''
l!l
01
MC/DC0%0/1
$prepend_tag || ''
$prepend_tag
MC/DC0%0/1
$append_tag || ''
$append_tag
Truth table50%1/2
A
A= $prepend_tag
Aresult
11
00
Truth table50%1/2
A
A= $append_tag
Aresult
11
00
672 <div$html>
673 } . ($prepend_tag || '') . qq{
674 $input_tag
675 } . ($append_tag || '') . qq{
676 </div>
677 };
678  
679 1 return out($tag);
680  
681 }
682  
683 1 ▶sub fix_input_ender {
Subroutine fix_input_ender: called CC=9 SCAR=31.8
Pod undocumented
684 1 my $c = shift;
685 1 my $ender = shift;
686 1 my $where = shift;
687  
688 1 ▶ if(ref $ender eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ender eq "") 0 1 1
689 0 return qq{<span class="input-group-addon">$ender</span>};
690 }
691  
692 1 my $key = (keys $ender->%*)[0];
693 1 my $tag = undef;
694 1 ▶ if($key eq 'check_box' || $key eq 'radio_button') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq 'check_box' or $key eq 'radio_button') { } 1 0 1
elsif ($key eq 'button') { } 0 0 0
elsif ($key eq 'buttongroup') { } 0 0 0
Condition33%1/3
$key eq "check_box" or $key eq "radio_button"
l!l&&r!l&&!r
100
MC/DC0%0/2
$key eq "check_box" or $key eq "radio_button"
$key eq "check_box" $key eq "radio_button"
Truth table33%1/3
A or B
A= $key eq "check_box"B= $key eq "radio_button"
ABresult
1X1
011
000
695 1 ▶ my $type = $key eq 'check_box' ? 'checkbox' : 'radio';
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'check_box' ? : 1 0 1
696 1 my $extra_input = Mojolicious::Plugin::TagHelpers::_input($c, $ender->{ $key }->@*, type => $type);
697 1 $tag = qq{
698 <span class="input-group-addon">$extra_input</span>
699 };
700 }
701 elsif($key eq 'button') {
702 0 my $button = bootstrap_button($c, $ender->{ $key }->@*);
703 0 $tag = qq{
704 <span class="input-group-btn">$button</span>
705 };
706 }
707 elsif($key eq 'buttongroup') {
708 0 ▶ return '' if ref $ender->{ $key } ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $ender->{$key} ne "ARRAY" 0 0 0
709 my($button_group) = scalar $ender->{ $key }->@* == 1 ? make_dropdown_meat($c, $ender->{ $key }[0]->@*)
710 0 ▶ : make_buttongroup_meat($c, $ender->{ $key }->@*)
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$ender->{$key}} == 1 ? : 0 0 0
711 ;
712 0 $tag = qq{
713 <div class="input-group-btn">$button_group</div>
714 }
715 }
716 0 else { $tag = $key; }
717  
718 1 return $tag;
719 }
720  
721 7 ▶sub iscoderef {
Subroutine iscoderef: called CC=1 SCAR=0.0
Pod undocumented
722 7 return ref shift eq 'CODE';
723 }
724 11 ▶sub url_for {
Subroutine url_for: called CC=4 SCAR=14.0
Pod undocumented
725 11 my $c = shift;
726 11 my $url = shift;
727 11 ▶ return '' if ref $url ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $url ne "ARRAY" 0 11 11
728 11 ▶ return $url->[0] if scalar $url->@* == 1 && substr ($url->[0], 0, 1) eq '#';
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$url == 1 and substr($url->[0], 0, 1) eq "#" 5 6 11
Condition66%2/3
scalar @$url == 1 and substr($url->[0], 0, 1) eq "#"
!ll&&!rl&&r
065
MC/DC50%1/2
scalar @$url == 1 and substr($url->[0], 0, 1) eq "#"
scalar @$url == 1 substr($url->[0], 0, 1) eq "#"
Truth table66%2/3
A and B
A= scalar @$url == 1B= substr($url->[0], 0, 1) eq "#"
ABresult
0X0
100
111
729 6 return $c->url_for($url->@*)->to_string;
730 }
731  
732 2 ▶sub fix_input {
Subroutine fix_input: called CC=10 SCAR=26.2
Pod undocumented
733 2 my $c = shift;
734 2 my $attr = shift;
735  
736 2 my $tagname;
737 my $info;
738  
739 2 ▶ if((grep { exists $attr->{"${_}_field"} } qw/date datetime month time week color email number range search tel text url password/)[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if ((grep {exists $$attr{"${_}_field"};} 'date', 'datetime', 'month', 'time', 'week', 'color', 'email', 'number', 'range', 'search', 'tel', 'text', 'url', 'password')[0]) { } 2 0 2
elsif (exists $attr->{'text_area'}) { } 0 0 0
740 2 $tagname = (grep { exists $attr->{"${_}_field"} } qw/date datetime month time week color email number range search tel text url password/)[0];
741 2 $info = $attr->{"${tagname}_field"};
742 }
743 elsif(exists $attr->{'text_area'}) {
744 0 $tagname = 'textarea';
745 0 $info = $attr->{'text_area'};
746 }
747 2 my $id = shift $info->@*;
748  
749 # if odd number of elements, the first one is the value (shortcut to avoid having to: value => 'value')
750 2 ▶ if($info->@* % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$info % 2) 0 2 2
751 0 push $info->@* => (value => shift $info->@*);
752 }
753 2 my $tag_attr = { $info->@* };
754  
755 2 my @column_classes = get_column_classes($attr->{'column_information'}, 1);
756 2 $tag_attr = add_classes($tag_attr, 'form-control', { size => 'input-%s' });
757  
758 2 ▶ $tag_attr->{'id'} = $id if defined $id && !exists $tag_attr->{'id'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $id and not exists $tag_attr->{"id"} 2 0 2
Condition33%1/3
defined $id and not exists $tag_attr->{"id"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $id and not exists $tag_attr->{"id"}
defined $id not exists $tag_attr->{"id"}
Truth table33%1/3
A and not(B)
A= defined $idB= not exists $tag_attr->{"id"}
ABresult
0X0
100
111
759 2 ▶ my $name_attr = defined $id ? $id =~ s{-}{_}rg : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 2 0 2
760  
761 2 $tag_attr = cleanup_attrs($tag_attr);
762  
763 2 ▶ my $horizontal_before = scalar @column_classes ? qq{<div class="} . (trim join ' ' => @column_classes) . '">' : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @column_classes ? : 0 2 2
764 2 ▶ my $horizontal_after = scalar @column_classes ? '</div>' : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @column_classes ? : 0 2 2
765 2 ▶ my $input = exists $attr->{'text_area'} ? Mojolicious::Plugin::TagHelpers::_text_area($c, $name_attr, delete $tag_attr->{'value'}, $tag_attr->%*)
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'text_area'} ? : 0 2 2
766 : Mojolicious::Plugin::TagHelpers::_input($c, $name_attr, $tag_attr->%*, type => $tagname)
767 ;
768  
769 2 return ($id => $horizontal_before . $input . $horizontal_after);
770  
771 }
772  
773 1 ▶sub fix_label {
Subroutine fix_label: called CC=2 SCAR=7.0
Pod undocumented
774 1 my $c = shift;
775 1 my $for = shift;
776 1 my $title = shift;
777 1 my $attr = shift;
778  
779 1 my @column_classes = get_column_classes($attr->{'column_information'}, 0);
780 1 my @args = (class => trim join ' ' => ('control-label', @column_classes));
781 1 ▶ ref $title eq 'CODE' ? push @args => $title : unshift @args => $title;
Branch: 1 branch
BranchTrueFalseTotal
ref $title eq 'CODE' ? : 0 1 1
782  
783 1 return Mojolicious::Plugin::TagHelpers::_label_for($c, $for, @args);
784 }
785  
786 1 ▶sub parse_call {
Subroutine parse_call: called CC=3 SCAR=11.2
Pod undocumented
787 1 my $c = shift;
788 1 my $title = shift;
789 1 ▶ my $callback = ref $_[-1] eq 'CODE' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'CODE' ? : 0 1 1
790 1 ▶ my $content = scalar @_ % 2 ? pop : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ % 2 ? : 0 1 1
791 1 my $attr = parse_attributes(@_);
792  
793 1 return ($c, $title, $callback, $content, $attr);
794 }
795  
796 44 ▶sub parse_attributes {
Subroutine parse_attributes: called CC=4 SCAR=21.7
Pod undocumented
797 44 my %attr = @_;
798 44 ▶ if($attr{'data'} && ref $attr{'data'} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{"data"} and ref $attr{"data"} eq "HASH") 0 44 44
Condition33%1/3
$attr{"data"} and ref $attr{"data"} eq "HASH"
!ll&&!rl&&r
4400
MC/DC0%0/2
$attr{"data"} and ref $attr{"data"} eq "HASH"
$attr{"data"} ref $attr{"data"} eq "HASH"
Truth table33%1/3
A and B
A= $attr{"data"}B= ref $attr{"data"} eq "HASH"
ABresult
0X0
100
111
799 0 ▶ while(my($key, $value) = each %{ $attr{'data'} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$attr{"data"};}) 0 0 0
800 0 $key =~ tr/_/-/;
801 0 $attr{ lc("data-$key") } = $value;
802 }
803 0 delete $attr{'data'};
804 }
805 44 return \%attr;
806 }
807  
808 3 ▶sub get_column_classes {
Subroutine get_column_classes: called CC=3 SCAR=14.2
Pod undocumented
809 3 my $attr = shift;
810 3 my $index = shift;
811  
812 3 my @classes = ();
813 3 foreach my $key (keys $attr->%*) {
814 0 my $correct_name = get_size_for($key);
815 0 ▶ if(defined $correct_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $correct_name) 0 0 0
816 0 push @classes => sprintf "col-%s-%d" => $correct_name, $attr->{ $key }[ $index ];
817 }
818 }
819 3 return sort @classes;
820 }
821  
822 47 ▶sub add_classes {
Subroutine add_classes: called CC=9 SCAR=22.0
Pod undocumented
823 47 my $attr = shift;
824 47 ▶ my $formatter = ref $_[-1] eq 'HASH' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 22 25 47
825  
826 16 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
827  
828 47 my @classes = ($attr->{'class'}, @_);
829  
830 47 ▶ if($formatter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatter) 22 25 47
831 22 ▶ if(exists $formatter->{'size'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"size"}) 18 4 22
832 18 push @classes => sprintfify_class($attr, $formatter->{'size'}, $formatter->{'size_default'}, _sizes());
833 }
834 22 ▶ if(exists $formatter->{'button'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"button"}) 11 11 22
835 11 push @classes => sprintfify_class($attr, $formatter->{'button'}, $formatter->{'button_default'}, _button_contexts());
836 }
837 22 ▶ if(exists $formatter->{'panel'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"panel"}) 1 21 22
838 1 push @classes => sprintfify_class($attr, $formatter->{'panel'}, $formatter->{'panel_default'}, _panel_contexts());
839 }
840 22 ▶ if(exists $formatter->{'table'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"table"}) 1 21 22
841 1 push @classes => sprintfify_class($attr, $formatter->{'table'}, $formatter->{'table_default'}, _table_contexts());
842 }
843 22 ▶ if(exists $formatter->{'direction'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"direction"}) 1 21 22
844 1 push @classes => sprintfify_class($attr, $formatter->{'direction'}, $formatter->{'direction_default'}, _direction_contexts());
845 }
846 22 ▶ if(exists $formatter->{'navbar'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $formatter->{"navbar"}) 1 21 22
847 1 push @classes => sprintfify_class($attr, $formatter->{'navbar'}, $formatter->{'navbar_default'}, _navbar_contexts());
848 }
849 }
850  
851 47 my %uniqs = ();
852 47 $attr->{'class'} = trim join ' ' => uniq sort @classes;
853  
854 47 return $attr;
855  
856 }
857  
858 33 ▶sub sprintfify_class {
Subroutine sprintfify_class: called CC=4 SCAR=13.9
Pod undocumented
859 33 my $attr = shift;
860 33 my $format = shift;
861 33 my $possibilities = pop;
862 33 my $default = shift;
863  
864 33 my @founds = (grep { exists $attr->{ $_ } } (keys $possibilities->%*));
865  
866 33 ▶ return if !scalar @founds && !defined $default;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @founds or defined $default 19 14 33
Condition100%3/3
scalar @founds or defined $default
l!l&&r!l&&!r
31119
MC/DC100%2/2
scalar @founds or defined $default
scalar @founds defined $default
Truth table100%3/3
A or B
A= scalar @foundsB= defined $default
ABresult
1X1
011
000
867 14 ▶ push @founds => $default if !scalar @founds;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @founds 11 3 14
868  
869 14 return map { sprintf $format => $possibilities->{ $_ } } @founds;
870  
871 }
872  
873 17 ▶sub add_disabled {
Subroutine add_disabled: called CC=4 SCAR=17.9
Pod undocumented
874 17 my $attr = shift;
875 17 my $add_as_class = shift; # if false, add as attribute
876  
877 17 ▶ if(exists $attr->{'__disabled'} && $attr->{'__disabled'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"__disabled"} and $attr->{"__disabled"}) 0 17 17
Condition66%2/3
exists $attr->{"__disabled"} and $attr->{"__disabled"}
!ll&&!rl&&r
1160
MC/DC0%0/2
exists $attr->{"__disabled"} and $attr->{"__disabled"}
exists $attr->{"__disabled"} $attr->{"__disabled"}
Truth table66%2/3
A and B
A= exists $attr->{"__disabled"}B= $attr->{"__disabled"}
ABresult
0X0
100
111
878 0 ▶ if($add_as_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_as_class) { } 0 0 0
879 0 $attr = add_classes($attr, 'disabled');
880 }
881 else {
882 0 $attr->{'disabled'} = 'disabled';
883 }
884 }
885 17 return $attr;
886 }
887  
888 1 ▶sub contents {
Subroutine contents: called CC=2 SCAR=7.1
Pod undocumented
889 1 my $callback = shift;
890 1 my $content = shift;
891  
892 1 ▶ return defined $callback ? $callback->() : xml_escape($content);
Branch: 1 branch
BranchTrueFalseTotal
defined $callback ? : 0 1 1
893 }
894  
895 11 ▶sub content_single {
Subroutine content_single: called CC=2 SCAR=7.2
Pod undocumented
896 11 my $content = shift;
897  
898 11 ▶ return ref $content eq 'CODE' ? $content->() : xml_escape($content);
Branch: 1 branch
BranchTrueFalseTotal
ref $content eq 'CODE' ? : 0 11 11
899 }
900  
901 58 ▶sub cleanup_attrs {
Subroutine cleanup_attrs: called CC=2 SCAR=6.9
Pod undocumented
902 58 my $hash = shift;
903  
904 #* delete all shortcuts (-> __*)
905 58 map { delete $hash->{ $_ } } grep { substr($_, 0, 2) eq '__' } keys $hash->%*;
906  
907 #* delete all keys whose value is not a string
908 58 ▶ map { delete $hash->{ $_ } } grep { $_ ne 'data' && ref $hash->{ $_ } ne '' } keys $hash->%*;
Condition66%2/3
$_ ne 'data' && ref $hash->{$_} ne ''
!ll&&!rl&&r
0901
MC/DC50%1/2
$_ ne 'data' && ref $hash->{$_} ne ''
$_ ne 'data' ref $hash->{$_} ne ''
Truth table66%2/3
A && B
A= $_ ne 'data'B= ref $hash->{$_} ne ''
ABresult
0X0
100
111
909  
910 58 return $hash;
911 }
912  
913 0 ▶sub get_size_for {
Subroutine get_size_for: not called CC=1 SCAR=6.9
Pod undocumented
914 0 my $input = shift;
915  
916 0 return _sizes()->{ $input };
917 }
918  
919 18 ▶sub _sizes {
Subroutine _sizes: called CC=1 SCAR=0.0
920 return {
921 18 __xsmall => 'xs', xsmall => 'xs', xs => 'xs',
922 __small => 'sm', small => 'sm', sm => 'sm',
923 __medium => 'md', medium => 'md', md => 'md',
924 __large => 'lg', large => 'lg', lg => 'lg',
925 }
926 }
927  
928 11 ▶sub _button_contexts {
Subroutine _button_contexts: called CC=1 SCAR=0.0
929 11 return { map { ("__$_" => $_, $_ => $_) } qw/default primary success info warning danger link/ };
930 }
931 1 ▶sub _panel_contexts {
Subroutine _panel_contexts: called CC=1 SCAR=0.0
932 1 return { map { ("__$_" => $_, $_ => $_) } qw/default primary success info warning danger/ };
933 }
934 1 ▶sub _table_contexts {
Subroutine _table_contexts: called CC=1 SCAR=0.0
935 1 return { map { ("__$_" => $_, $_ => $_) } qw/striped bordered hover condensed responsive/ };
936 }
937 1 ▶sub _direction_contexts {
Subroutine _direction_contexts: called CC=1 SCAR=0.0
938 1 return { map { ("__$_" => $_, $_ => $_) } qw/right block vertical justified dropup left/ };
939 }
940 0 ▶sub _menu_contexts {
Subroutine _menu_contexts: not called CC=1 SCAR=6.9
941 0 return { map { ("__$_" => undef, $_ => undef) } qw/caret hamburger/ };
942 }
943 0 ▶sub _misc_contexts {
Subroutine _misc_contexts: not called CC=1 SCAR=6.9
944 0 return { map { ("__$_" => $_, $_ => $_) } qw/active disabled/ };
945 }
946 1 ▶sub _navbar_contexts {
Subroutine _navbar_contexts: called CC=1 SCAR=0.0
947 1 return { map { ("__$_" => $_, $_ => $_) } qw/default inverse/ };
948 }
949  
950 36 ▶sub out {
Subroutine out: called CC=1 SCAR=0.0
Pod undocumented
951 36 my $tag = shift;
952 36 return Mojo::ByteStream->new($tag);
953 }
954  
955 16 1;
956  
957 __END__
↑ Summary BootstrapHelpers.pm »