FormHandler/Render/Util.pm

filter: Statementstmt 100% 46 / 46 Branchbran 62.5% 10 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 85.3% 64 / 75 CC 11 SCAR 15.8
CC
11
Cov
89%
process_attrs
8.2
cc_widget
3.1
ucc_widget
2.0
CRAP 4.9
« FormHandler/Field/IntRange.pm ↑ Summary FormHandler/Field/RequestToken.pm »
1 package HTML::FormHandler::Render::Util;
2 # ABSTRACT: rendering utility
3 151 $HTML::FormHandler::Render::Util::VERSION = '0.410002';
4 151 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 151 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 151 ▶use Sub::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 151 Sub::Exporter::setup_exporter({ exports => [ 'process_attrs', 'cc_widget', 'ucc_widget' ] } );
8 151 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # this is a function for processing various attribute flavors
12 2261 ▶sub process_attrs {
Subroutine process_attrs: called CC=8 SCAR=21.0
Pod undocumented
13 2261 my ($attrs) = @_;
14  
15 2261 my @use_attrs;
16 2261 ▶ my $javascript = delete $attrs->{javascript} || '';
Condition50%1/2
delete $attrs->{'javascript'} || ''
l!l
02261
MC/DC0%0/1
delete $attrs->{'javascript'} || ''
delete $attrs->{'javascript'}
Truth table50%1/2
A
A= delete $attrs->{'javascript'}
Aresult
11
00
17 2261 for my $attr( sort keys %$attrs ) {
18 978 my $value = '';
19 978 ▶ if( defined $attrs->{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{$attr}) 978 0 978
20 978 ▶ if( ref $attrs->{$attr} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attrs->{$attr} eq 'ARRAY') { } 515 463 978
21 # we don't want class="" if no classes specified
22 515 ▶ next unless scalar @{$attrs->{$attr}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$attrs->{$attr};} 0 515 515
23 515 $value = join (' ', @{$attrs->{$attr}} );
24 }
25 else {
26 463 $value = $attrs->{$attr};
27 }
28 }
29 # we use double quotes as the delimiter so only html encode those
30 # HTML attribute context
31 # as we use double quotes we need to encode those
32 # & is the html encoding character and therefore needs encoding as well
33 978 push @use_attrs, sprintf( '%s="%s"', $attr, encode_entities($value, '"&') );
34 }
35 2261 my $output = join( ' ', @use_attrs );
36 2261 ▶ $output = " $output" if length $output;
Branch: 1 branch
BranchTrueFalseTotal
if length $output 760 1501 2261
37 2261 ▶ $output .= " $javascript" if $javascript;
Branch: 1 branch
BranchTrueFalseTotal
if $javascript 0 2261 2261
38 2261 return $output;
39 }
40  
41 4 ▶sub cc_widget {
Subroutine cc_widget: called CC=3 SCAR=11.2
Pod undocumented
42 4 my $widget = shift;
43 4 ▶ return '' unless $widget;
Branch: 1 branch
BranchTrueFalseTotal
unless $widget 0 4 4
44 4 ▶ if($widget eq lc $widget) {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget eq lc $widget) 4 0 4
45 4 $widget =~ s/^(\w{1})/\u$1/g;
46 4 $widget =~ s/_(\w{1})/\u$1/g;
47 }
48 4 return $widget;
49 }
50  
51 199 ▶sub ucc_widget {
Subroutine ucc_widget: called CC=2 SCAR=7.0
Pod undocumented
52 199 my $widget = shift;
53 199 ▶ if($widget ne lc $widget) {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget ne lc $widget) 199 0 199
54 199 $widget =~ s/::/_/g;
55 199 $widget = ucfirst($widget);
56 199 my @parts = $widget =~ /([A-Z][a-z]*)/g;
57 199 $widget = join('_', @parts);
58 199 $widget = lc($widget);
59 }
60 199 return $widget;
61 }
62  
63  
64 151 1;
65  
66 __END__
« FormHandler/Field/IntRange.pm ↑ Summary FormHandler/Field/RequestToken.pm »