| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FormHandler::Render::Util; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: rendering utility |
|
3
|
|
|
|
|
|
|
$HTML::FormHandler::Render::Util::VERSION = '0.40068'; |
|
4
|
146
|
|
|
146
|
|
57891
|
use Sub::Exporter; |
|
|
146
|
|
|
|
|
12667
|
|
|
|
146
|
|
|
|
|
1355
|
|
|
5
|
|
|
|
|
|
|
Sub::Exporter::setup_exporter({ exports => [ 'process_attrs', 'cc_widget', 'ucc_widget' ] } ); |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# this is a function for processing various attribute flavors |
|
9
|
|
|
|
|
|
|
sub process_attrs { |
|
10
|
2185
|
|
|
2185
|
0
|
4737
|
my ($attrs) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
2185
|
|
|
|
|
4108
|
my @use_attrs; |
|
13
|
2185
|
|
50
|
|
|
9440
|
my $javascript = delete $attrs->{javascript} || ''; |
|
14
|
2185
|
|
|
|
|
8876
|
for my $attr( sort keys %$attrs ) { |
|
15
|
951
|
|
|
|
|
2115
|
my $value = ''; |
|
16
|
951
|
50
|
|
|
|
2568
|
if( defined $attrs->{$attr} ) { |
|
17
|
951
|
100
|
|
|
|
2576
|
if( ref $attrs->{$attr} eq 'ARRAY' ) { |
|
18
|
|
|
|
|
|
|
# we don't want class="" if no classes specified |
|
19
|
495
|
50
|
|
|
|
889
|
next unless scalar @{$attrs->{$attr}}; |
|
|
495
|
|
|
|
|
1529
|
|
|
20
|
495
|
|
|
|
|
947
|
$value = join (' ', @{$attrs->{$attr}} ); |
|
|
495
|
|
|
|
|
1436
|
|
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
else { |
|
23
|
456
|
|
|
|
|
938
|
$value = $attrs->{$attr}; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
} |
|
26
|
951
|
|
|
|
|
4833
|
push @use_attrs, sprintf( '%s="%s"', $attr, $value ); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
2185
|
|
|
|
|
5563
|
my $output = join( ' ', @use_attrs ); |
|
29
|
2185
|
100
|
|
|
|
6499
|
$output = " $output" if length $output; |
|
30
|
2185
|
50
|
|
|
|
5347
|
$output .= " $javascript" if $javascript; |
|
31
|
2185
|
|
|
|
|
7632
|
return $output; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub cc_widget { |
|
35
|
4
|
|
|
4
|
0
|
8
|
my $widget = shift; |
|
36
|
4
|
50
|
|
|
|
11
|
return '' unless $widget; |
|
37
|
4
|
50
|
|
|
|
14
|
if($widget eq lc $widget) { |
|
38
|
4
|
|
|
|
|
30
|
$widget =~ s/^(\w{1})/\u$1/g; |
|
39
|
4
|
|
|
|
|
22
|
$widget =~ s/_(\w{1})/\u$1/g; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
4
|
|
|
|
|
22
|
return $widget; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub ucc_widget { |
|
45
|
199
|
|
|
199
|
0
|
608
|
my $widget = shift; |
|
46
|
199
|
50
|
|
|
|
786
|
if($widget ne lc $widget) { |
|
47
|
199
|
|
|
|
|
1008
|
$widget =~ s/::/_/g; |
|
48
|
199
|
|
|
|
|
562
|
$widget = ucfirst($widget); |
|
49
|
199
|
|
|
|
|
1275
|
my @parts = $widget =~ /([A-Z][a-z]*)/g; |
|
50
|
199
|
|
|
|
|
647
|
$widget = join('_', @parts); |
|
51
|
199
|
|
|
|
|
542
|
$widget = lc($widget); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
199
|
|
|
|
|
1149
|
return $widget; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
HTML::FormHandler::Render::Util - rendering utility |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.40068 |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The 'process_attrs' takes a hashref and creates an attribute string |
|
76
|
|
|
|
|
|
|
for constructing HTML. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $attrs => { |
|
79
|
|
|
|
|
|
|
some_attr => 1, |
|
80
|
|
|
|
|
|
|
placeholder => 'Enter email...", |
|
81
|
|
|
|
|
|
|
class => ['help', 'special'], |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
|
|
|
|
|
|
my $string = process_attrs($attrs); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
...will produce: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
' some_attr="1" placeholder="Enter email..." class="help special"' |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
If an arrayref is empty, it will be skipped. For a hash key of 'javascript' |
|
90
|
|
|
|
|
|
|
only the value will be appended (without '$key=""'); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Gerda Shank. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
101
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |