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.40067'; |
4
|
144
|
|
|
144
|
|
49897
|
use Sub::Exporter; |
|
144
|
|
|
|
|
9344
|
|
|
144
|
|
|
|
|
1099
|
|
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
|
2174
|
|
|
2174
|
0
|
2075
|
my ($attrs) = @_; |
11
|
|
|
|
|
|
|
|
12
|
2174
|
|
|
|
|
1855
|
my @use_attrs; |
13
|
2174
|
|
50
|
|
|
6628
|
my $javascript = delete $attrs->{javascript} || ''; |
14
|
2174
|
|
|
|
|
6175
|
for my $attr( sort keys %$attrs ) { |
15
|
947
|
|
|
|
|
936
|
my $value = ''; |
16
|
947
|
50
|
|
|
|
1673
|
if( defined $attrs->{$attr} ) { |
17
|
947
|
100
|
|
|
|
1604
|
if( ref $attrs->{$attr} eq 'ARRAY' ) { |
18
|
|
|
|
|
|
|
# we don't want class="" if no classes specified |
19
|
493
|
50
|
|
|
|
436
|
next unless scalar @{$attrs->{$attr}}; |
|
493
|
|
|
|
|
974
|
|
20
|
493
|
|
|
|
|
515
|
$value = join (' ', @{$attrs->{$attr}} ); |
|
493
|
|
|
|
|
890
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
454
|
|
|
|
|
527
|
$value = $attrs->{$attr}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
947
|
|
|
|
|
3301
|
push @use_attrs, sprintf( '%s="%s"', $attr, $value ); |
27
|
|
|
|
|
|
|
} |
28
|
2174
|
|
|
|
|
4080
|
my $output = join( ' ', @use_attrs ); |
29
|
2174
|
100
|
|
|
|
3956
|
$output = " $output" if length $output; |
30
|
2174
|
50
|
|
|
|
3139
|
$output .= " $javascript" if $javascript; |
31
|
2174
|
|
|
|
|
5081
|
return $output; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub cc_widget { |
35
|
4
|
|
|
4
|
0
|
7
|
my $widget = shift; |
36
|
4
|
50
|
|
|
|
12
|
return '' unless $widget; |
37
|
4
|
50
|
|
|
|
15
|
if($widget eq lc $widget) { |
38
|
4
|
|
|
|
|
38
|
$widget =~ s/^(\w{1})/\u$1/g; |
39
|
4
|
|
|
|
|
27
|
$widget =~ s/_(\w{1})/\u$1/g; |
40
|
|
|
|
|
|
|
} |
41
|
4
|
|
|
|
|
22
|
return $widget; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub ucc_widget { |
45
|
199
|
|
|
199
|
0
|
414
|
my $widget = shift; |
46
|
199
|
50
|
|
|
|
456
|
if($widget ne lc $widget) { |
47
|
199
|
|
|
|
|
259
|
$widget =~ s/::/_/g; |
48
|
199
|
|
|
|
|
322
|
$widget = ucfirst($widget); |
49
|
199
|
|
|
|
|
751
|
my @parts = $widget =~ /([A-Z][a-z]*)/g; |
50
|
199
|
|
|
|
|
346
|
$widget = join('_', @parts); |
51
|
199
|
|
|
|
|
267
|
$widget = lc($widget); |
52
|
|
|
|
|
|
|
} |
53
|
199
|
|
|
|
|
752
|
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.40067 |
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) 2016 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 |