pQuery where p = Perl
Date : 2008 02 28 Category : Tech & DevelopmentWe have talked about a pQuery before, which was a PHP port of jQuery. Now we have a new pQuery for the Perl community:
pQuery is a pragmatic attempt to port the jQuery JavaScript framework to Perl. It is pragmatic in the sense that it switches certain JavaScript idioms for Perl ones, in order to make the use of it concise. A primary goal of jQuery is to "Find things and do things, concisely". pQuery has the same goal.
pQuery exports a single function called pQuery. This function acts a constructor and does different things depending on the arguments you give it.
A pQuery object acts like an array reference (because, in fact, it is). Typically it is an array of HTML::DOM elements, but it can be an array of anything.
Like jQuery, pQuery methods return a pQuery object; either the original object or a new derived object. All pQuery METHODS are described below.
PLAIN TEXT PERL:use pQuery;
pQuery("http://google.com/search?q=pquery")
->find("h2.r")
->each(sub {
my $i = shift;
print ($i + 1), ") ", pQuery($_)->text, "n";
});
It is always interesting to see ideas ported from Web JavaScript to other languages.