Name : perl-Apache2-Ajax
| |
Version : 0.11
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp154.8.1
| Date : 2023-01-27 17:59:36
|
Group : Development/Libraries/Perl
| Source RPM : perl-Apache2-Ajax-0.11-lp154.8.1.src.rpm
|
Size : 0.02 MB
| |
Packager : https://www_suse_com/
| |
Summary : mod_perl interface to CGI::Ajax
|
Description :
This module is a mod_perl2 interface to CGI::Ajax, which provides a mechanism for using perl code asynchronously from javascript-enhanced HTML pages.
As well as mod_perl2, this package requires CGI::Ajax, as well as a CGI.pm-compatible CGI module for supplying the _param()_ and _header()_ methods. If available, CGI::Apache2::Wrapper will be used, which is a minimal module that uses methods of mod_perl2 and Apache2::Request to provide these methods; if this is not available, CGI (version 2.93 or greater) will be used.
Setting things up can be illustrated by the following example of CGI::Ajax, which contains a more thorough discussion, as well as a number of illustrative example scripts.
* * Define a Perl subroutine
At least one Perl subroutine must be defined which takes input from some form element and returns a result. For example,
sub evenodd_func { my $input = shift; $input % 2 == 0 ? return(\"EVEN\") : return(\"ODD\"); }
will accept an argument from a form element and return a string indicating if that number is even or odd.
Note that, in this module, only Perl subroutines are used, whereas in CGI::Ajax, references to subroutines may also be used.
* * Generate the web page
A subroutine is provided which generates the html for the web page. Within this is a trigger which calls the Perl subroutine, as well as the particular HTML div element to which the results are sent. For example,
sub Show_HTML { my $html = < < EOT; < HTML> < HEAD>< title>A Simple Example< /title> < /HEAD> < BODY> Enter a number: < input type=\"text\" name=\"somename\" id=\"val1\" size=\"6\" OnKeyUp=\"evenodd( [\'val1\'], [\'resultdiv\'] );\"> < br> < hr> < div id=\"resultdiv\"> < /div> < /BODY> < /HTML> EOT
return $html; }
By means of either an Apache configuration directive or arguments passed into the constructor for the object, to be described later, the Perl subroutine _evenodd_func_ defined earlier will be associated with a JavaScript function _evenodd_. This function is triggered using the _OnKeyUp_ event handler of the input HTML element. The subroutine takes one value from the form, the input element _val1_, and returns the the result to an HTML div element with an id of _resultdiv_.
There may be circumstances under which it is desireable to generate the html page directly within a handler, rather than through a subroutine as described above. This is possible, but one is then responsible for inserting the JavaScript code directly into the page, which can be done with the _show_javascript()_ method described later. The following is a a handler which illustrates this technique:
sub handler { my $r = shift; my $my_func = sub { my $arg = shift; return ( $arg . \" with some extra\" ); }; my $ajax = Apache2::Ajax->new($r, tester => $my_func); my $html = \"\"; $html .= \"< HTML>\"; $html .= \"< HEAD>\";
$html .= $ajax->show_javascript;
$html .= < < EOT; < /HEAD> < BODY> < FORM name=\"form\"> < INPUT type=\"text\" id=\"inarg\" onkeyup=\"tester([\'inarg\'],[\'output_div\']); return true;\"> < hr> < div id=\"output_div\">< /div> < /FORM> < br/>< div id=\'pjxdebugrequest\'>< /div>< br/> < /BODY> < /HTML> EOT
my $cgi = $ajax->cgi; my $pjx = $ajax->pjx; $cgi->header();
if ( not $cgi->param(\'fname\') ) { $r->print($html); } else { $r->print($pjx->handle_request()); } return Apache2::Const::OK; }
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-A/15.4/noarch |