HTML::Element::Replacer

Simplify the HTML::Element clone() - push_content() ritual
Download

HTML::Element::Replacer Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Terrence Brannon
  • Publisher web site:
  • http://search.cpan.org/~tbone/

HTML::Element::Replacer Tags


HTML::Element::Replacer Description

Simplify the HTML::Element clone() - push_content() ritual Let's say you have the following HTML: < table > < tr scla="top"/ > < tr scla="mid" > < td kmap="brand" > blah < /td > < td kmap="age" > blah < /td > < /tr> < tr scla="bot"/ > < /table >Now let's say you have 5 data rows that you wish to display using the middle tr as your sample. The pure HTML::Tree way to do this would be: my $sample_tr = $tree->look_down(scla => 'mid'); my @c; for my $data (@data) { my $c = $sample_tr->clone; $c->defmap(kmap => $data); push @c, $c; } $sample->replace_with(@c);We did cheat a bit by using defmap() from HTML::Element::Library. Now, with this class, we can do this: { my $replacer = HTML::Element::Replacer->new(look_down => ); for my $data (@data) { my $clone = $replacer->push_clone->defmap(kmap => $data); # clone and push onto @temp_list } } # replacer goes out of scope and then replaces sample_trSYNOPSIS use HTML::Element::Replacer; { my $replacer = HTML::Element::Replacer->new(tree => $tree, look_down => ); for my $data (@data) { $replacer->push_clone->defmap(attr_name => $data); # clone and push onto @temp_list } } # by default Replacer replaces... so it removes the element you were push_clone()ing Requirements: · Perl


HTML::Element::Replacer Related Software