Tuesday·14·February·2006
an XPath engine that can be re-used by other classes that implement trees
Michel Rodriguez, the XML genius, has done it again. First it was with
XML::Twig.
Now, he has implemented Tree::XPathEngine
to allow to XPath usage on any tree module that implements the
required methods!
// show without comments // write a comment // Trackback URL
Wednesday·01·February·2006
HTML::Seamstress::new_from_file() now reblesses the whole tree
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');
// show without comments // write a comment // Trackback URL
Friday·27·January·2006
Literal text in attributes of HTML::Element nodes
I had to create an attribute for an HTML::Element like this:
// show without comments // write a comment // Trackback URL
Good articles from Perl.com
- Massive Data Aggregation with Perl by Fred Moyer
- Shows how to do a mod-perl based upload and give the user constant feedback via Javascript
- More Advancements in Perl Programming
- has a great piece on Yahoo’s public API for getting keywords from a document.
// show without comments // write a comment // Trackback URL
Thursday·26·January·2006
Catalyst SVN
How to check out the Catalyst CPAN distro via SVN
How to import sources
Browse for the directory you want thens!browser!repos/Catalyst!
e.g.:
svn import CatalystAdvent-Seamstress/
http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/CatalystAdvent-Seamstress
maps to http://dev.catalyst.perl.org/browser/trunk/examples/CatalystAdvent-Seamstress
// show without comments // write a comment // Trackback URL
Wednesday·25·January·2006
When writing Seamstress pages, componentize your tree transforms
Working with our Mason codebase today showed me something that would have been a lot harder in Seamstress. Basically, I was told to add a vonage advertisement in another table cell everywhere that we displayed a vbase_banner.
Up to this point, all pages using the vbase_banner looked something like this:
<& 'comp/related_topics_lander_2', aconf => $aconf, query => $query &>
<& 'comp/vbase_banner', aconf => $aconf, query => $query, align => 'left' &>
% if ($query->{'brand'} eq 'tbar') {
<& 'comp/tbar_foot', aconf => $aconf, query => $query &>
% } else {
<& 'comp/quickfoot', aconf => $aconf, query => $query, align => 'center' &>
% }
<& 'comp/footer', aconf => $aconf, query => $query &>
|
So all I had to do was toss a bit of logic in vbase_banner for the vonage_ad and I was done:
|
|
% if ($query->{pagetype} ne ‘KEY’) {
<& vonage_ad &>
% } |
|
With Seamstress, one could componentize a page by creating subroutines for processing each part, but one does not have to. This is a downfall in Seamstress in a sense. But nevertheless, with Params::Validate and HTML::Tree, one can still do the trick, but one must be disciplined about placing each tree transformation into a separate subroutine instead of having a subroutine with a series of
The end result of disciplined Seamstress usage is that you can refine subroutines and make wholesale changes across several webpages if they all point to the same place
// show without comments // write a comment // Trackback URL
Terrence Brannon
Matthew Sisk
