View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Mahmoud A. Mehyar > jQuery-0.004 > jQuery



Annotate this POD


New  4
Open  0
View/Report Bugs
Module Version: 0.004   Source  


jQuery - complete jQuery port to Perl


    ##OOP style
    use jQuery;
    my $j = jQuery->new('');
    ##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("p")->append( sub{
        my $i = shift;
        my $html = shift;
        return "<strong>Hello</strong>";
    } )->css('color','red');
    print jQuery->as_HTML;


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


Caveats ^

When dealing with multiple HTML document at once always use OO style

    my $j1 = jQuery->new($html1);
    my $j2 = jQuery->new($html2);
    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

    ##always use a new constructure when switching documents
    ##the previous will be lost
    my $nodes = jQuery('div');
    $nodes->find('..')->css('border','1px solid red');

Dependencies ^

    * XML::LibXML 1.70 and later
    * LWP::UserAgent
    * HTML::Entities
    * HTTP::Request::Common


To install this module type the following:

   perl Makefile.PL
   make test
   make install

Methods ^

See jQuery::Functions

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


Mamod A. Mehyar, <>


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.

syntax highlighting: