##
Date Time Page
Date Time Page
The current date and time is
4:44pm on the dot
##
##
package index;
sub new {
my $that = shift;
my $class = ref( $that ) || $that;
my $this = {
class_map => {
date_time => \&date_time,
},
# other stuff you want here ...
};
return bless $this, $class;
}
sub date_time {
my( $this, $node, $class, $is_end_tag ) = @_;
($node->children())[0]->text( `date` );
}
##
##
HTML
Conditional HTML
Conditional HTML
This page will show a table when the calculated random numer is odd.
Here is what we calculated :
dummy text
which has a modulus of
dummy text
yo ho ho
and a bottle
of rum, son
let's have fun!
Perl
package index;
srand (time ^ $$ );
sub new {
my $that = shift;
my $class = ref( $that ) || $that;
my $this = {
class_map => {
calc_random => \&calc_random,
show_random => \&show_random,
show_tab => \&show_tab,
},
# other stuff you want here ...
};
return bless $this, $class;
}
sub calc_random {
my( $this, $node, $class, $is_end_tag ) = @_;
return 0 if $is_end_tag;
$this->{random} = sprintf '%d', rand(1000);
return 1;
}
sub show_random {
my( $this, $node, $class, $is_end_tag ) = @_;
return 0 if $is_end_tag;
$this->{display} = ($this->{random} % 2);
($node->children())[0]->text( $this->{random});
return 1;
}
1;
##
##
billy_bob
123
456
789
101
666
sub next_row {
my( $this, $node, $class, $is_end_tag ) = @_;
return 1 if $is_end_tag;
my $row = shift @{$this->{ps_table}};
return 0 if !$row;
my @row = split /\s+/, $row;
@{$this}{qw(USER PID CPU MEM TIME COMMAND)} =
(@row[0..3],@row[9,10]);
return 1;
}
##
##
my $row = shift @{$this->{ps_table}};
return 0 if !$row;
##
##
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:
HOHOHO
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;