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