| Next |
Los Angeles Perl Mongers |
7 |
require 'simple-class.pl';
use HTML::Seamstress;
# load the view
my $seamstress = HTML::Seamstress->new_from_file('simple.html');
# load the model
my $o = Simple::Class->new;
$seamstress->table
(
# tell seamstress where to find the table, via the method call
# ->look_down('id', $gi_table). Seamstress detaches the table from the
# HTML tree automatically if no table rows can be built
gi_table => 'load_data',
# tell seamstress where to find the tr. This is a bit useless as
# the <tr> usually can be found as the first child of the parent
gi_tr => 'iterate',
# the model data to be pushed into the table
table_data => $o->load_data,
# the way to take the model data and obtain one row
# if the table data were a hashref, we would do:
# my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key}
tr_data => sub { my ($self, $data) = @_;
shift(@{$data}) ;
},
# the way to take a row of data and fill the <td> tags
td_data => sub { my ($tr_node, $tr_data) = @_;
$tr_node->content_handler($_ => $tr_data->{$_})
for qw(name age weight) }
);
print $seamstress->as_HTML;