sub row {
# $tab is a number.
# $type is one of the keys from the %types table below.
# $cells is an array ref list of the cells in the row.
my ($tab,$type,$cells) = @_;
my %types = (
header => 'h',
data => 'd',
whead => 'd'
);
line($tab,qq(
));
# Rows which start with a header need to have the first cell
# shifted off to receive the th tag.
if ($type eq 'whead') {
my $cell = shift @{$cells};
cell($tab + 1,'h',ucfirst $cell, { class => 'row_header' });
}
# Most cells do not need anything special so the contents can be passed
# as $value, however if the cell needs formatting or other attributes,
# it can be passed as an array ref [$contents, { ... options ... }].
my $cell_type = $types{$type};
for my $cell (@{$cells}) {
if (ref($cell) eq 'ARRAY') {
cell($tab + 1,$cell_type,$cell->[0],$cell->[1]);
}
else {
cell($tab + 1,$cell_type,$cell);
}
}
line($tab,q(
));
}