HTML
The Reformed Data
The Reformed Data
You requested to have your data formatted into
300,00 columns:
And here is your wonderful data:
blah blah blah
And now displayed as a table:
Perl
package index;
sub new {
my $that = shift;
my $class = ref( $that ) || $that;
my $this = {
class_map => {
show_no_rows => \&show_no_rows,
show_data => \&show_data,
reform_data => \&reform_data,
table_row => \&table_row,
td => \&td,
},
# other stuff you want here ...
};
return bless $this, $class;
}
sub show_no_rows {
my( $this, $node, $class, $is_end_tag ) = @_;
return 0 if $is_end_tag;
$this->{rows} = $this->{ r }->param('no_rows');
($node->children())[0]->text( $this->{rows} );
return 1;
}
sub show_data {
my( $this, $node, $class, $is_end_tag ) = @_;
return 0 if $is_end_tag;
$this->{data} = [ split /\s+/, $this->{ r }->param('data') ];
($node->children())[0]->text( $this->{r}->param('data' ) );
return 1;
}
sub reform_data {
use Array::Reform;
my( $this, $node, $class, $is_end_tag ) = @_;
return 0 if $is_end_tag;
warn "no_rows: $this->{rows}";
$this->{reform_data} =
[ Array::Reform->reform($this->{rows}, $this->{data} ) ];
use Data::Dumper;
warn Data::Dumper->Dump([$this->{reform_data}],['reform_data']);
return 1;
}
sub table_row {
my( $this, $node, $class, $is_end_tag ) = @_;
warn 'table_row';
return 1 if $is_end_tag;
my $rows= $this->{rows};
$this->{td} = shift @{$this->{reform_data}};
warn "THIS_TD: @{$this->{td}}";
return 0 if !$this->{td};
return 1;
}
sub td {
my( $this, $node, $class, $is_end_tag ) = @_;
warn 'td';
return 1 if $is_end_tag;
my $rows= $this->{rows};
my $td = shift @{$this->{td}};
return 0 if !$td;
($node->children())[0]->text($td);
return 1;
}
1;