| 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'} || ''
MC/DC0%0/1
delete $attrs->{'javascript'} || ''
delete $attrs->{'javascript'}
Truth table50%1/2
A
A= delete $attrs->{'javascript'}
| |||||||||||||
| 17 | 2261 | for my $attr( sort keys %$attrs ) { | |||||||||||
| 18 | 978 | my $value = ''; | |||||||||||
| 19 | 978 | ▶ | if( defined $attrs->{$attr} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 978 | ▶ | if( ref $attrs->{$attr} eq 'ARRAY' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | # we don't want class="" if no classes specified | ||||||||||||
| 22 | 515 | ▶ | next unless scalar @{$attrs->{$attr}}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 37 | 2261 | ▶ | $output .= " $javascript" if $javascript; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 44 | 4 | ▶ | if($widget eq lc $widget) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||