use HTML::Seamstress;
# load the view
my $seamstress = HTML::Seamstress->new_from_file('simple.html');
# load the model
my $o = Simple::Class->new;
my $data = $o->load_data;
# find the
and
my $table_node = $seamstress->look_down('id', 'load_data');
my $iter_node = $table_node->look_down('id', 'iterate');
my $table_parent = $table_node->parent;
# drop the sample and from the HTML
# only add them in if there is data in the model
# this is achieved via the $add_table flag
$table_node->detach;
$iter_node->detach;
my $add_table;
# Get a row of model data
while (my $row = shift @$data) {
++$add_table;
# clone the sample
my $new_iter_node = $iter_node->clone;
# find the tags labeled name age and weight and
# set their content to the row data
$new_iter_node->content_handler($_ => $row->{$_})
for qw(name age weight);
# push this table row onto the table
$table_node->push_content($new_iter_node);
}
# reattach the table to the HTML tree if we loaded data into some table rows
$table_parent->push_content($table_node) if $add_table;
print $seamstress->as_HTML;