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 , 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" stands for generic identifier. Most people call "gi"s tags, but # mirod calls them "gi"s so I will too :) gi_table => 'load_data', # tell seamstress where to find the . # this is the major place where DWIM will come in! gi_tr => 'iterate', # the model data to be pushed into the table, row by row 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
tags # content_handler() is a Seamstress function which takes # $id_val and $content as args. It does a ->look_down('id', $id_val) # and sets the content section of the found node (a ) to $content td_data => sub { my ($tr_node, $tr_data) = @_; $tr_node->content_handler($_ => $tr_data->{$_}) for qw(name age weight) } ); print $seamstress->as_HTML;