CGI-Application-Demo-Ajax
view release on metacpan or search on metacpan
lib/CGI/Application/Demo/Ajax.pm view on Meta::CPAN
This module is available as a Unix-style distro (*.tgz).
See http://savage.net.au/Perl-modules/html/installing-a-module.html for
help on unpacking and installing distros.
=head1 Installation
All these assume your doc root is /var/www.
=head2 Install YUI
Browse to http://developer.yahoo.com/yui/, download, and unzip into htdocs:
shell>cd /var/www
shell>sudo unzip ~/Desktop/yui_2.7.0b.zip
This creates /var/www/yui, and yui_url in .htajax.conf must match.
=head2 Install the module
Install this as you would for any C<Perl> module:
Unpack the distro, and then either:
perl Build.PL
./Build
./Build test
sudo ./Build install
or:
perl Makefile.PL
make (or dmake)
make test
make install
=head2 Install the C<HTML::Template> files.
shell>cd /var/www
shell>sudo mkdir -p assets/templates/cgi/application/demo/ajax
shell>cp distro's/htdocs/*.tmpl to assets/templates/cgi/application/demo/ajax
Alternately, edit the now installed .htajax.conf, to adjust tmpl_path.
=head2 Install the trivial instance script
shell>cp distro's/htdocs/ajax.cgi to /usr/lib/cgi-bin
shell>sudo chmod 755 /usr/lib/cgi-bin/ajax.cgi
=head2 Install the fancy instance script
shell>cd /var/www
shell>sudo mkdir local
shell>cp distro's/htdocs/ajax to local
shell>sudo chmod 755 local/ajax
=head2 Configure C<Apache> to use local/ajax
If in fancy mode, add these to httpd.conf:
LoadModule fcgid_module modules/mod_fcgid.so
and:
<Location /local>
SetHandler fcgid-script
Options ExecCGI
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
And restart C<Apache>.
=head2 Start searching
Point your broswer at http://127.0.0.1/cgi-bin/ajax.cgi (trivial script), or
http://127.0.0.1/local/ajax (fancy script, nice-and-clean URL).
=head1 The Flow of Control
Here's a step-by-step description of what's happening:
=over 4
=item You initialize the process
Point your web client at http://127.0.0.1/cgi-bin/ajax.cgi or http://127.0.0.1/local/ajax.
This is equivalent to C<< CGI::Application::Demo::Ajax -> new() -> run() >>.
Since there is no run mode input, the code defaults to Ajax.pm's sub initialize(). See sub setup() for details.
=item The code assembles the default web page
The work is done in Ajax.pm's sub initialize().
This page is sent from the server to the client.
It contains the contents of web.page.tmpl, with both search.js and search.tmpl embedded therein.
Of course, it also contains a minimal set of YUI Javascript files.
=item The client accepts the response
The default web page is displayed.
=item You input a search term
The C<CGI> form in search.tmpl is set to not submit, but rather to call the Javascript function search_onsubmit(),
which lives in search.js.
It's actually the copy of this code, now inside web.page.tmpl, now inside your client, which gets executed.
=item The C<CGI> form is submitted
Here, Javascript does the submit, in such a way as to also specify a call-back (Javascript) function, search_callback(),
which will handle the response from the server.
This function also lives in search.js.
=item Ajax.pm runs again
This time a run mode was submitted, either as form data or as path info data.
And this means that when using the fancy script, you don't need the line in search.tmp referring to the hidden form
( run in 1.727 second using v1.01-cache-2.11-cpan-5735350b133 )