NAME
jQuery - complete jQuery port to Perl
SYNOPSIS
##OOP style
use jQuery;
my $j = jQuery->new('http://someurl.com');
##or insert html directly
my $j = jQuery->new('<html>...</html>');
$j->jQuery('p')->append( sub {
my $i = shift;
my $html = shift;
return "<strong>Hello</strong>";
} )->css('color','red');
print $j->as_HTML;
##non OOP - more like jQuery.js style
jQuery->new($html);
jQuery("p")->append( sub{
my $i = shift;
my $html = shift;
return "<strong>Hello</strong>";
} )->css('color','red');
print jQuery->as_HTML;
DESCRIPTION
This is another attempt to port jQuery to Perl "the DOM part and what ever could be run on the server side NOT client side"
To create this module I went through jQuery.js and some times literally translated javascript functions to their perl equivalent, which made my job way easier than thinking of how and why I can do this or that. of course some other times I had to roll my own hacks :)
How this differ from other Perl jQuery modules?
First, I wrote this long time ago, I wasn't sure if there were any jQuery modules then or maybe I didn't search CPAN well, then later I found pQuery which is nice, clean and written by Ingy döt Net
Here are some differences
* it uses XML::LibXML as it's parsing engine
* Work just like jQuery.js. Translate jQuery.js by simply replace . with -> "with some minor twists"
* Almost all jQuery DOM functions are supported
jQuery
Method for matching a set of elements in a document
- jQuery( selector, [ context ] )
- jQuery( element )
- jQuery( elementArray )
- jQuery( jQuery object )
- jQuery( <html> )
this Method
this method in loop represents current selected node
jQuery('div')->each(sub{
this->addClass('hola');
});
Caveats
When dealing with multiple HTML document at once always use OO style
my $j1 = jQuery->new($html1);
my $j2 = jQuery->new($html2);
##then
$j1->jQuery('div')->find('..')->addClass('..');
my $nodes = $j2->('div');
$nodes->find('span')->css('border','1px solid red');
print $j1->as_HTML();
print $j2->as_HTML();
This way, different documents will never overlap, you may use the non OO style but you need to be careful then
jQuery->new($html1);
jQuery('div')->find('..')->addClass('..');
jQuery->as_HTML;
##always use a new constructure when switching documents
##the previous will be lost
jQuery->new($html2);
my $nodes = jQuery('div');
$nodes->find('..')->css('border','1px solid red');
jQuery->as_HTML;
Dependencies
* XML::LibXML 1.70 and later
* LWP::UserAgent
* HTML::Entities
* HTTP::Request::Common
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
Methods
Examples
Please see the included examples folder for more on how to use and supported functions All examples have been copied directly from jQuery document web site you can see their equivalent in jQuery api section at http://api.jquery.com/
AUTHOR
Mamod A. Mehyar, <mamod.mehyar@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2011 - 2013 by Mamod A. Mehyar
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 582:
Non-ASCII character seen before =encoding in 'döt'. Assuming CP1252