Wednesday·01·February·2006
HTML::Seamstress::new_from_file() now reblesses the whole tree //at 00:29 //by abe
To date, Seamstress has supported tree-based rewriting of HTML
trees by blessing the $tree into a class which has these
superclasses - HTML::Seamstress,
HTML::Element::Library, HTML::Element, and any local
Element library. That way, you can rewrite the $tree by
going:
$tree->this; $tree->that;Well, that was all good and fine until today when I tried to call this and that on a subtree of
$tree:
my $div = $tree->look_down('_tag' => 'div');
$div->this;
$div->that;
and it did not work because $div was blessed into
HTML::Element instead of a class which inherited from the
above-mentioned superclasses.
So, the solution was to simply bless all nodes of $tree
into the same class. A test case 02.treebless.t shows the new
functionality:
package tree::bless;
use Test::More qw(no_plan);
use TestUtils;
use base qw(HTML::Seamstress) ;
my $root = 't/html/treebless';
my $tree = __PACKAGE__->new_from_file("$root.html");
my $li = $tree->look_down(class => 'greg');
is (ref $li, 'tree::bless', 'blessed into proper class');
Filed under:
Perl Software Design Blog » perl » html-seamstress »
reblessing-whole-tree
// write a comment // comments off // Trackback URL
// write a comment // comments off // Trackback URL
Comments
