line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
875
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
455
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Element::SimpleTable; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Element::SimpleTable::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: simple table element |
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
48
|
use Moose; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
69
|
|
8
|
8
|
|
|
8
|
|
54395
|
use MooseX::Attribute::Chained; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
308
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element::Block'; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
48
|
use HTML::FormFu::Util qw( append_xml_attribute ); |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
520
|
|
12
|
8
|
|
|
8
|
|
56
|
use Scalar::Util qw( reftype ); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
399
|
|
13
|
8
|
|
|
8
|
|
53
|
use Carp qw( croak ); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
5361
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has odd_class => ( is => 'rw', traits => ['Chained'] ); |
16
|
|
|
|
|
|
|
has even_class => ( is => 'rw', traits => ['Chained'] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
after BUILD => sub { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$self->tag('table'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub headers { |
27
|
4
|
|
|
4
|
1
|
12
|
my ( $self, $headers ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
4
|
50
|
|
|
|
25
|
croak "headers must be passed as an array-ref" |
30
|
|
|
|
|
|
|
if reftype($headers) ne 'ARRAY'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# save any elements already added |
33
|
4
|
|
|
|
|
10
|
my @original_rows = @{ $self->_elements }; |
|
4
|
|
|
|
|
123
|
|
34
|
4
|
|
|
|
|
119
|
$self->_elements( [] ); |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
18
|
my $header_row = $self->element('Block'); |
37
|
4
|
|
|
|
|
114
|
$header_row->tag('tr'); |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
13
|
for my $text (@$headers) { |
40
|
7
|
|
|
|
|
23
|
my $th = $header_row->element('Block'); |
41
|
7
|
|
|
|
|
198
|
$th->tag('th'); |
42
|
7
|
|
|
|
|
30
|
$th->content($text); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
4
|
100
|
|
|
|
18
|
if (@original_rows) { |
46
|
3
|
|
|
|
|
6
|
push @{ $self->_elements }, @original_rows; |
|
3
|
|
|
|
|
91
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
19
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub rows { |
53
|
6
|
|
|
6
|
1
|
20
|
my ( $self, $rows ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
6
|
50
|
|
|
|
28
|
croak "too many arguments" if @_ > 2; |
56
|
|
|
|
|
|
|
|
57
|
6
|
50
|
|
|
|
31
|
croak "rows must be passed as an array-ref" |
58
|
|
|
|
|
|
|
if reftype($rows) ne 'ARRAY'; |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
16
|
for my $cells (@$rows) { |
61
|
10
|
50
|
|
|
|
43
|
croak "each row must be an array-ref" |
62
|
|
|
|
|
|
|
if reftype($cells) ne 'ARRAY'; |
63
|
|
|
|
|
|
|
|
64
|
10
|
|
|
|
|
61
|
my $row = $self->element('Block'); |
65
|
10
|
|
|
|
|
292
|
$row->tag('tr'); |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
27
|
for my $cell (@$cells) { |
68
|
15
|
|
|
|
|
123
|
my $td = $row->element('Block'); |
69
|
15
|
|
|
|
|
435
|
$td->tag('td'); |
70
|
15
|
|
|
|
|
50
|
$td->element($cell); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
6
|
|
|
|
|
23
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub render_data { |
78
|
4
|
|
|
4
|
0
|
23
|
return shift->render_data_non_recursive(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub render_data_non_recursive { # though it is really recursive |
82
|
10
|
|
|
10
|
0
|
33
|
my ( $self, $args ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
361
|
my $odd = $self->odd_class; |
85
|
10
|
|
|
|
|
335
|
my $even = $self->even_class; |
86
|
10
|
|
|
|
|
25
|
my $i = 1; |
87
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
20
|
for my $row ( @{ $self->get_elements } ) { |
|
10
|
|
|
|
|
90
|
|
89
|
19
|
|
|
|
|
81
|
my $first_cell = $row->get_element; |
90
|
|
|
|
|
|
|
|
91
|
19
|
100
|
100
|
|
|
457
|
if ( $i == 1 && $first_cell->tag eq 'th' ) { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# skip the header row |
94
|
5
|
|
|
|
|
18
|
next; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
14
|
100
|
|
|
|
55
|
if ( $i % 2 ) { |
98
|
10
|
100
|
|
|
|
43
|
if ( defined $odd ) { |
99
|
2
|
|
|
|
|
8
|
$row->attributes( { class => $odd } ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
4
|
100
|
|
|
|
14
|
if ( defined $even ) { |
104
|
1
|
|
|
|
|
5
|
$row->attributes( { class => $even } ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
14
|
|
|
|
|
35
|
$i++; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $render = $self->SUPER::render_data_non_recursive( |
111
|
10
|
50
|
|
|
|
57
|
{ elements => [ map { $_->render_data } @{ $self->_elements } ], |
|
19
|
|
|
|
|
74
|
|
|
10
|
|
|
|
|
311
|
|
112
|
|
|
|
|
|
|
$args ? %$args : (), |
113
|
|
|
|
|
|
|
} ); |
114
|
|
|
|
|
|
|
|
115
|
10
|
|
|
|
|
292
|
append_xml_attribute( $render->{attributes}, 'class', lc $self->type ); |
116
|
|
|
|
|
|
|
|
117
|
10
|
|
|
|
|
50
|
return $render; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=encoding UTF-8 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
HTML::FormFu::Element::SimpleTable - simple table element |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version 2.07 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
The following is yaml markup for a table consisting of a header row |
141
|
|
|
|
|
|
|
containing 2 C<th> cells, and a further 2 rows, each containing 2 C<td> |
142
|
|
|
|
|
|
|
cells. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
type: SimpleTable |
145
|
|
|
|
|
|
|
headers: |
146
|
|
|
|
|
|
|
- One |
147
|
|
|
|
|
|
|
- Two |
148
|
|
|
|
|
|
|
rows: |
149
|
|
|
|
|
|
|
- |
150
|
|
|
|
|
|
|
- type: Input |
151
|
|
|
|
|
|
|
name: one_a |
152
|
|
|
|
|
|
|
- type: Input |
153
|
|
|
|
|
|
|
name: two_a |
154
|
|
|
|
|
|
|
- |
155
|
|
|
|
|
|
|
- type: Input |
156
|
|
|
|
|
|
|
name: one_b |
157
|
|
|
|
|
|
|
- type: Input |
158
|
|
|
|
|
|
|
name: two_b |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 DESCRIPTION |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Sometimes you just really need to use a table to display some fields in a |
163
|
|
|
|
|
|
|
grid format. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
As its name suggests, this is a compromise between power and simplicity. |
166
|
|
|
|
|
|
|
If you want more control of the markup, you'll probably just have to revert |
167
|
|
|
|
|
|
|
to using nested L<block's|HTML::FormFu::Element::_Block>, setting the tags |
168
|
|
|
|
|
|
|
to table, tr, td, etc. and adding the cell contents as elements. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 METHODS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 headers |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Input Value: \@headers |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L</headers> accepts an arrayref of strings. Each string is xml-escaped and |
177
|
|
|
|
|
|
|
inserted into a new header cell. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 rows |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Input Value: \@rows |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
L</rows> accepts an array-ref, each item representing a new row. Each row |
184
|
|
|
|
|
|
|
should be comprised of an array-ref, each item representing a table cell. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Each cell item should be appropriate for passing to L<HTML::FormFu/element>; |
187
|
|
|
|
|
|
|
so either a single element's definition, or an array-ref of element |
188
|
|
|
|
|
|
|
definitions. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 odd_class |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Input Value: $string |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
The supplied string will be used as the class-name for each odd-numbered row |
195
|
|
|
|
|
|
|
(not counting any header row). |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 even_class |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Input Value: $string |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
The supplied string will be used as the class-name for each even-numbered row |
202
|
|
|
|
|
|
|
(not counting any header row). |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 SEE ALSO |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
207
|
|
|
|
|
|
|
L<HTML::FormFu::Element::Block>, |
208
|
|
|
|
|
|
|
L<HTML::FormFu::Element> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L<HTML::FormFu> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 LICENSE |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
219
|
|
|
|
|
|
|
the same terms as Perl itself. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
230
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |