NAME

CGI::Perljax - a perl-specific system for writing AJAX- or DHTML-based web applications.

SYNOPSIS

use CGI::Perljax;
my $pjx = new CGI::Perljax( 'exported_func1' => \&perl_func1 );

DESCRIPTION

Perljax is an object-oriented module that provides a unique mechanism for using perl code asynchronously from javascript-enhanced web pages. You would commonly use Perljax in AJAX/DHTML-based web applications. Perljax unburdens the user from having to write any javascript, except for having to associate an exported method with a document-defined event (such as onClick, onKeyUp, etc). Only in the more advanced implementations of a exported perl method would a user need to write any javascript.

Perljax supports methods that return single results, or multiple results to the web page, and the after version >= 0.20, supports returning values to multiple DIV elements on the HTML page.

Using Perljax, the URL for the HTTP GET request is automatically generated based on HTML layout and events, and the page is then dynamically updated. We also have support for mapping URL's to a CGI::Perljax function name, so you can separate your code processing over multiple scripts.

Other than using the Class::Accessor module to generate Perljaxs' accessor methods, Perljax is completely self-contained - it does not require you to install a larger package or a full Content Management System.

A primary goal of CGI::Perljax is to keep the module streamlined and maximally flexible. We are trying to keep the generated javascript code to a minimum, and provide users with a variety of methods for deploying CGI::Perljax in their own applications.

USAGE

Create a CGI object to send to Perljax, export the subroutines prior to creating the Perljax object, like so:

  use strict;
  use CGI::Perljax;
  use CGI;

  # define a normal perl subroutine that you want available 

    sub evenodd_func {
    my $input = shift;
    
    # see if input is defined
    if ( not defined $input ) {
      return("input not defined or NaN");
    }

    # see if value is a number (*thanks Randall!*)
    if ( $input !~ /\A\d+\z/ ) {
      return("input is NaN");
    }

    # got a number, so mod by 2
    $input % 2 == 0 ? return("EVEN") : return("ODD");

  }

  # define a function to generate the web page - this can be done
  # million different ways, and can also be defined as an anonymous sub.
  # The only requirement is that the sub send back the html of the page.

  sub Show_HTML {
    my $html = <<EOT;

  <HTML>
  <HEAD><title>Perljax Example</title>
  </HEAD>
  <BODY>
    Enter a number:&nbsp;
    <input type="text" name="val1" id="val1" size="6"
       onkeyup="evenodd( ['val1'], 'resultdiv' );
       return true;"><br>
    <hr>
    <div id="resultdiv" style="border: 1px solid black;
          width: 440px; height: 80px; overflow: auto">
    </div>
  </BODY>
  </HTML>
  EOT

    return $html;
  }

  my $cgi = new CGI();  # create a new CGI object

  # create a Perljax object, and associate our anon code
  # In >= version 0.20 of CGI::Perljax, you can make the associated
  # code a url to another CGI script.

  my $pjx = new CGI::Perljax( 'evenodd' => \&evenodd_func );

	# print the form sending in the cgi and the HTML function
  
  # this outputs the html for the page
  print $pjx->build_html($cgi,\&Show_HTML);

METHODS

build_html()
    Purpose: associate cgi obj ($cgi) with pjx object, insert
		         javascript into <HEAD></HEAD> element
  Arguments: either a coderef, or a string containing html
    Returns: html or updated html (including the header)
  Called By: originating cgi script
show_javascript()
  Purpose: builds the text of all the javascript that needs to be
           inserted into the calling scripts html header
Arguments: 
  Returns: javascript text
Called By: originating web script
     Note: This method is also overridden so when you just print
           a Perljax object it will output all the javascript needed
           for the web page.

BUGS

SUPPORT

Check out the sourceforge discussion lists at:

http://www.sourceforge.net/projects/pjax

AUTHORS

Brian C. Thomas     Brent Pedersen
CPAN ID: BCT
bct.x42@gmail.com   bpederse@gmail.com

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

Class::Accessor, CGI

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 127:

'=item' outside of any '=over'

Around line 150:

You forgot a '=back' before '=head1'