####
use HTML::Element::Replacer;
my @beer =
(
{ brand => 'miller', age => 12 },
{ brand => 'coors' , age => 15 },
{ brand => 'coke' , age => 22 }
);
my @fruit =
(
{ fruit => 'apple' , color => 'red' },
{ fruit => 'orange' , color => 'orange' },
{ fruit => 'banana' , color => 'yellow' }
);
# table_example is a Perl package that creates an
# HTML::TreeBuilder instance of the file table_example.html
# actually it creates an HTML::Seamstress instance, but
# HTML::Seasmtress @ISA HTML::Tree
use table_example;
my $tree = table_example->new;
{
my $replacer = HTML::Element::Replacer->new
(tree => $tree,
look_down => [ seam_class => 'beer_row' ]);
for my $data (@beer) {
# defmap is in HTML::Element::Library
$replacer->push_clone->defmap(kmap => $data);
}
}
# BRACES ARE NECESSARY for HTML::Element::Replacer to work!
{
use List::Cycle;
my $row_style = List::Cycle->new( { values => [ qw/main alt/ ] } ) ;
my $replacer = HTML::Element::Replacer->new
(tree => $tree,
look_down => [ seam_class => 'fruit_row' ]);
for my $data (@fruit) {
my $elem = $replacer->push_clone;
$elem->defmap(kmap => $data); # clone and push onto @temp_list
$elem->attr(row_style => $row_style->next);
}
}
warn $tree->as_HTML(undef, ' ');
####
[tbrannon@devel tables]$ spkg.pl --base_pkg=Base file.html
comp_root........ /home/tbrannon/prg/html-element-replacer/HTML-Element-Replacer/ex/tables/
html_file_path... /home/tbrannon/prg/html-element-replacer/HTML-Element-Replacer/ex/tables/
html_file........ file.html
html_file sans... file
file.html compiled to package file
####
package Base;
use base qw(HTML::Seamstress) ;
sub comp_root { '/home/tbrannon/prg/html-element-replacer/HTML-Element-Replacer/ex/tables' }
1;