CGI-Ajax-0.707/0000755000175000017500000000000011073174173013162 5ustar bpedersebpederseCGI-Ajax-0.707/LICENSE0000644000175000017500000005010111053027714014160 0ustar bpedersebpederseTerms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS --------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End CGI-Ajax-0.707/META.yml0000644000175000017500000000100711073174173014431 0ustar bpedersebpederse--- #YAML:1.0 name: CGI-Ajax version: 0.707 abstract: CGI::Ajax license: ~ generated_by: ExtUtils::MakeMaker version 6.36 distribution_type: module requires: CGI: 0 Class::Accessor: 0 Test::Simple: 0.44 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 author: - Brian C. Thomas (bct.x42@gmail.com) Brent Pedersen (bpederse@gmail.com) CGI-Ajax-0.707/Todo0000644000175000017500000000020111053027714013777 0ustar bpedersebpederseTODO list for Perl module CGI::Perljax More docs. Add ability to override default param name of 'fname' if the user desires. CGI-Ajax-0.707/MANIFEST0000644000175000017500000000153711073174173014321 0ustar bpedersebpederseMANIFEST LICENSE README Todo Changes lib/CGI/Ajax.pm t/001_load.t t/002_load.t scripts/pjx_cr.pl scripts/pjx_podex.pl scripts/pjx_subs.pl scripts/pjx_manyret.pl scripts/pjx_combo.pl scripts/pjx_callback.pl scripts/pjx_chained.pl scripts/pjx_radio.pl scripts/pjx_url.pl scripts/pjx_nobuild.pl scripts/convert_degrees.pl scripts/pjx_splitargs.pl scripts/pjx_NO_CACHE_callee.pl scripts/pjx_NO_CACHE_caller.pl scripts/pjx_JSON.pl scripts/pjx_JSON_out.pl scripts/pjx_loading.pl scripts/pjx_formDump.pl scripts/pjx_change_encoding.pl scripts/pjx_change_headers.pl scripts/pjx_checkbox.pl scripts/pjx_dynselect.pl scripts/pjx_from_span.pl scripts/pjx_objects_2_url.pl scripts/CGI-Application-Ajax-ex01.pl scripts/CGI-Application-Ajax-ex02.pl scripts/CGI-Application-Ajax-ex03.pl Makefile.PL META.yml Module meta-data (added by MakeMaker) CGI-Ajax-0.707/README0000644000175000017500000000311511053027714014036 0ustar bpedersebpedersepod2text CGI::Perljax.pm > README CGI::Perljax Perljax - a perl-specific system for writing AJAX- or DHTML-based web applications. Perljax provides a unique mechanism for using perl code asynchronously from javascript using AJAX to access user-written perl functions/methods. 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 custom javascript. Perljax supports methods that return single results, or multiple results to the web page. No other projects that we know of are like Perljax for the following reasons: 1. Perljax is targeted specifically for perl development. 2. Perljax shields the user from having to write any javascript at all (unless they want to). 3. The URL for the HTTP GET request is automatically generated based on HTML layout and events, and the page is then dynamically updated. 4. Perljax is not part of a Content Management System, or some other larger project. INSTALL perl Makefile.PL make make test make install *If you are on a windows box you should use 'nmake' rather than 'make'. Installation will place Perljax into the system perl @INC path, but it is important that you make sure mod_perl uses this path (which is mod_perl's default behavior, and also assuming you use mod_perl, and not just run perl as a CGI). Example scripts are provided in the source script directory, and can also be seen on the project's website, http://www.perljax.us. CGI-Ajax-0.707/Changes0000644000175000017500000003736311073174036014467 0ustar bpedersebpederseRevision history for Perl module CGI::Perljax 0.707 (154) | Jan Franczak | 2008-10-07 Fixed an issue in the declaration of the javascript cache variable as a local variable in the exported methods. This was causing NO_CACHE to never generate the pjxrand in the query string. Changed the code so that cache is set as a global javascript variable. Thanks to Shivanandham Karunanithi for identifying this. 0.706 (153) | Shibi Ns | 2008-09-04 Wrongly coded one line of code for the fix 0.705 Changed this: # return '' if $cgi->isa('header') || $cgi->isa('header_type') ; To this: # return '' if $cgi->isa('CGI') || $cgi->isa('CGI::Application') ; 0.705 (152) | Shibi Ns | 2008-08-26 Changed function call from "can" to "isa" in order this to work with new version of CGI 3.37. CGI 3.37 has overloaded the function "can" which causes some of the functions to fail. 0.703 (150) | Jan Franczak | 2008-08-20 Added support for CACHE() which allows default behaviour of disabling page cache. Added fname() support to allow the names of exported functions to be specified. Added skip_header support to prevent two headers being produced for applications producing their own headers. Two new test scripts. 0.701 (141) | bpederse | 2007-01-30 added short docs about: onclick=jsfunc([{args:42}],['resultdiv']) as an alternative to: onclick=jsfunc(['args__42'],['resultdiv']) added fix for split made changes from Peter Gordon for CGI::Application and added 3 of his test scripts which are 1:1 mappings of our test cases. added changes to getval by Kyraha always show error regardless of debug level if $@ is filled after eval {} ---- OLDER UPDATES BELOW --- .26 Fri Aug 26 08:07:24 2005 original version; created by ExtUtils::ModuleMaker 0.36 .27 removed Perljax.pm .28 2005-09-07 10:14:54 Wed, 07 Sep 2005 the user can now send in static parameters on the function call: the fnargs has been renamed to 'args' the user can use a parameter as : onclick=(['args__1234','div'],['result']) which will form the url &args=1234&args=valueindiv can also rename parameters via: onclick=(['parname__'+getVal('div')],['result']) which will for the url: &parname=valueindiv this is useful for sending to outside scripts which may not use 'args' as the cgi parameter name. renamed getElem to getVal .32 2005-09-08 14:49:29 Thu, 08 Sep 2005 the url will now be appended to so if get parameters are on the initial url, they can be used in the registered ajax function Lot's of documentation and some code restructures. Set CPAN version to 0.32 .37 2005-09-12 10:41:13 Mon, 12 Sep 2005 changed perldoc some. Added newline/space compresson to show_common_js(). Fixed anonymous javascript functions to have semicolons after definition. Added JSDEBUG triggered compression of user-exported javascript wrapper functions. If JSBEDUG is on, the don't compress, otherwise compress Incremented CPAN version to 0.37 .43 2005-09-22 09:00:09 Thu, 22 Sep 2005 Fixed missing space in a javascript warning message when an HTML element id wasn't defined. Fixed bug in js code to support 'textarea' fields as well as 'test' can now use POST variables!! no url limit can take POST variables, previous addition was still broken. updated POST methods in javascript incremented version string to .43 - POD touchups added new example showing multiple returns to a page (pjx_manyret.pl, in scripts/ dir) .46 2005-09-28 14:10:08 -0700 Wed, 28 Sep 2005 Added a new example script to show using select boxes, which change the value of other select boxes based on what was selected. .47 2005-09-28 16:49:31 -0700 Wed, 28 Sep 2005 added support for multiple select boxes after bug report from aztecpawn on sourceforge.net. Now the common javascript will return an array of values if there was a multiple selection in a select box .49 2005-09-29 08:36:37 -0700 Thu, 29 Sep 2005 Fixed broken fnsplit so it wouldn't split strings. Restructured javascript code for spaces and indents. Need to give Brent my vimrc to prevent real tab chars from coming through. Removed all tab chars and replaced with spaces. Made lots of changes to pjx_combo.pl to better document and organize the html layout. .52 2005-10-05 11:14:27 -0700 Wed, 05 Oct 2005 Complete rewrite of POD documentation and expansion of documentation. Added heretofore undocumented capability of sending POST instead of the default GET. .55 2005-10-07 09:33:28 -0700 Fri, 07 Oct 2005 Can now chain functions; ajax[] array holds pjx objects, so pjx objects don't keep overwriting themselves. Cleaned up javascript custom function code. .56 2005-10-07 10:35:33 -0700 Fri, 07 Oct 2005 Changed debugging output for javascript to show multiple URLs is there are chained commands. Fixed a bug introduced in .55 that broke IE browsers - IE doesn't support onload, so switched back to onreadystatechange. .57 2005-10-10 09:24:37 -0700 Mon, 10 Oct 2005 Added radio to scripts directory; Added ability to handle radios; Fixed ghr so it only checks once on page load and returns a closure of the correct xmlhttp/activeX request object Changed name of 'radio.pl' to 'pjx_radio.pl' Version to .58 .59 2005-10-10 09:35:49 -0700 Mon, 10 Oct 2005 Version incremented to .59. Modified Changes and MANIFEST. Modified output of pjx_radio.pl. fix docs in pjx_radio Fixed bug reported by anonymous on SF about encodeURIComponent encoding '='. Problem was parens were mislocated. .591 fixed .59 bug that didn't fix the encodeURIComponent bug .60 2005-10-17 12:45:31 -0700 Mon, 17 Oct 2005 Fixed problem with javascript in make_function() where sep variable was getting overwritten if the processed url contained a '?'. Thanks to pavfed98 for identifying this - reported via rt.cpan.org. Added scripts/pjx_url.pl and scripts/convert_degrees.pl to scripts. These were needed to properly test the make_function handling of outside URLs (related to above bug). Added support to pass in additional information to build_html() function that gets sent directly to the cgi objects header() call. This allows for custom HTML header information to get sent to the pages generated in the CGI::Ajax system. Thanks to Jesper Dalberg for suggesting this. Modifiedcorrected docs. Updated to version 0.60 .64 2005-10-27 09:45 -0700 Thu, 27 Oct 2005 Fixed cross-site scripting vulnerability identified in the <=0.60 versions. All users of CGI::Ajax should upgrade asap! If a browser submits a request for a CGI::Ajax page that contains a function that doesn't exist, a status 400 Bad Request is returned. Additionally, STDERR gets some output about this event with a "SECURITY" tag, just in case. Thanks to krusch for catching this! Changed how CGI extra header parameters are passed into the CGI object. Now all parameters destined to CGI->header() are added as a hashref to the CGI::Ajax->build_html() method, like this for example $pjx->build_html( $cgi, \&Show_HTML, {-charset=>'UTF-8'} ); Any pre-0.64 CGI::Ajax script that passed in extra header information to the CGI object will be updating. Modified/corrected docs to explain the above change. Fixed up javascript code to make all loop variables local. Thanks to Mingyi Lui. .641 2005-10-27 12:54 -0700 Thu, 27 Oct 2005 Pod documentations fixups. Changed fnsplit to better support multiple selects (thanks Mingyi Lui) ------------------------------------------------------------------------ .65 2005-10-27 12:55 -0700 Thu, 27 Oct 2005 pod typo corrections changed javascript fnsplit to better support multiple-selects styles add pjx_callback.pl to demonstrate the use of a callback function. this required a fix in the Ajax.pm code Fixed up synopsis example POD. .651 2005-11-02 07:32 -0800 Wed, 02 Nov 2005 added support for hidden fields. .652 2005-11-03 13:41 -0800 fixed type in javascript for handling hidden fields! updated version and Changes to reflect .652 release .653 | bcthomas | 2005-11-14 18:42:42 moved some debugging code around so perl can handle the jdebug state. Thanks beanz! Added a script (pjx_nobuild.pl) to demonstrate not using build_html() but to instead handle the various stages of the async communication manually. Fixed up POD .654 | bcthomas | 2005-11-15 10:38:55 Added fix for redundant js if test back in. Thanks again beanz Updated MANIFEST to show new no build_html() script and incremented version to 0.654 0.66 | bcthomas | 2005-11-29 10:22 POD cleanup/corrections Added support for other CGI handlers/decoders (like CGI::Simple, CGI::Lite, CGI::Minimal, although we can't really test them since we are running mod_perl2 only here. Fixed typo in pjx_url.pl/convert_degrees.pl that was reversing the sign on the kelvin degree conversion (thanks Wolfgang Baron!) Switched home page URL to www.perljax.us Updated version to 0.66 0.662 | bcthomas | 2005-12-01 12:15 POD cleanup/corrections Added a example script to show proper way to use a javascript function to split arguments returned from a perl-exported function. scripts/pjx_splitargs.pl Updated version to 0.662 0.67 | bcthomas | 2005-12-01 16:29 reversed quick fix for javascript handling return values from perl functions added in 0.662. now multiple returns to a callback function are handled as arguments[0], arguments[1], etc. uses an eval in the javascript code, the way it was described in the POD, but wasn't coded. changed splitargs.pl: added value="" to 's getting the return values from the function call to stop weird javascript warning Updated to 0.67 0.68 | bcthomas | 2005-12-09 11:51:25 changed splitargs.pl added value="" to 's getting the return values from the function call to stop weird javascript warning Fixed docs in Ajax.pm to reflect the old way of dealing with arguments array in javascript, after brent's fix of this code. Updated changes, and MANIFEST. Added ability to prevent caching (though firefox doesn't seem to cache anyway). The keyword is 'NO_CACHE'. Added to example scripts pjx_NO_CACHE_callee.pl and pjx_NO_CACHE_caller.pl, to demonstrate how no caching works. Fixed IE bug where __pjx____pjx__ doesn't return "" as the second split. Took a suggestion by 'qbxk' from the perljax.us forums and changed the javascript code so only the function names remain the same. Also rearranged code for javascript jsdebug() so it cuts down the amout of code. Moved getting the script name to Perl code. OVerall, these changes result in less repetition in the javascript functions. The URL length only includes the script name if it is calling itself. POD cleanup and additions. Added extra level to JSDEBUG to uncompress ALL generated javascript. Changed around some js varable names to be more understandable. Corrected several of the demo scripts to not use the original method of setting the div id to return results to... onkeyup=myfunc(['in1'],'out1') should be.. onkeyup=myfunc(['in1'],['out1']) (thanks Jerrod) Modified Changes and MANIFEST. Changed comments in Todo and README. Update version to 0.68 0.681 | bpederse | 2005-12-12 15:22:32 fixed the $script regular expression to work on windows; 0.682 | bcthomas | 2006-01-09 09:41 switched from encodeURIComponent to encodeURI fixed getVal to have better error checking, plus more inuitive code. also, use can now use name= (but getVal still looks for id= first) to send in the html element name. all code changes in javascript getVal(); This fix should alleviate mistakes where your HTML elements don't have an "id" defined, but do have a "name" defined. Rewrote docs in several areas. Removed gratuitous acks in javascript code. Added documentation about returning multiple arguments from perl to a javascript function. 0.683 | bpederse | 2006-01-20 13:27:43 Add scripts to show the use of JSON objects. Fixed radio and multiple-select (slight error); Cleaned up fnsplit. version to 0.683 0.684 | bpederse | 2006-01-28 added pjx_loading.pl script. added function formDump() which returns an array of all form element names/ids in the page and sends them to the function: onclick=jsFunc(formDump(),['out']) add pjx_formDump.pl to the scripts directory documneting use. also changed getVal so that if you send in a function, it will return the result of the function, not hte function itself. also added $() and an alias to getVal() to follow prototype.js but, might be a bad idea since even in the HERE delimiters '>>' you have to escape the '$'.. 0.69 (105) | bcthomas | 2006-02-16 fixed typo in pjx_chained.pl Updated MANIFEST/Changes for release 0.684 Added support for spans Added callback methods in javascript: pjx.prototype.pjxInitialized and pjx.prototype.pjxCompleted These methods are called before and after, respectively, any xmlhttp request. It was much more responsive this way rather than providing a hook into each readyState, especially since there is not uniform support for the various readyStates in the common browsers. Changed the pjx_loading.pl script to use the above callbacks, and documented it. Switched from prototype to javascript object notation. This is cosmetic, and only changes the way the code looks, not the way it functions. Added the ability to change the encoding that CGI::Ajax uses on input elements. The default is encodeURIComponent, but this can be set to encode, etc., like so... $pjx->js_encode_function('escape'); ...where 'escape' can be any of ('escape','encodeURI','encodeURIComponent') or a programmer-defined javascript function. altered MANIFEST to add two new scripts scripts/pjx_change_encoding.pl scripts/pjx_change_headers.pl Rearranged Class::Accessor initialization. Fixed select problem mentioned on forums, and changed pjx_formDump.pl as a test for that fix. updated to 0.69 0.691 (113) | bpederse | 2006-02-19 fixed decode-ing if encoding is 'encode*' , decoding is decode* if encoding is escape, decoding is unescape 0.692 (116) | bpederse | 2006-03-08 Wrapped a rogue debugging comment in an appropriate debugging check. changed pjx_nobuild to use 'pjxdebugrequest' instead of old '__pjxrequest' version to 0.692 0.693 (118) | bpederse | 2006-03-16 - javascript is now inserted at beggining of header, not before - the eval in the javascript is gone. replaced by apply. - using that apply "this" in a callback will now refer to the javascript object. so this.url will give the url of the AJAX request. 0.694 (119) | bcthomas | 2006-03-18 Added pjx_dynselect.pl to scripts in the dist. This example demonstrates the same thing as the pjx_combo.pl example, but it uses a simple database to get values, instead of the calling script (as in pjx_combo.pl). fixed all the additional scripts that were missing '
' tags. fixed pjx_combo.pl for IE compatibility, all options must have a value, for example here are the wrong way and the right way for IE... NO: YES: fixed checkboxes - added a check script for them. updated some indentation in examples 0.697 (134) | bpederse | 2006-07-15 two new demo scripts can now get input from anything with .innerHTML (pjx_from_span.pl as test case). Changed the default encode function to 'escape' instead of 'encodeURIComponent'. Hopefully this will alleviate many of the problems users are reporting with browser functionality. fixed problem with head/body with arguments (also improved regexp speed) add the ability to send in arguments via javascript objects instead of using args__123, now can use {'args':123, 'args':'bcd','test':'the value'} fixed selects. see notes in previous checkin. added $ENV{SCRIPT_FILENAME} CGI-Ajax-0.707/Makefile.PL0000644000175000017500000000103611053027714015130 0ustar bpedersebpederse use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'CGI::Ajax', VERSION_FROM => 'lib/CGI/Ajax.pm', # finds \$VERSION AUTHOR => 'Brian C. Thomas (bct.x42@gmail.com) Brent Pedersen (bpederse@gmail.com)', ABSTRACT => 'CGI::Ajax', PREREQ_PM => { 'Test::Simple' => 0.44, 'Class::Accessor' => 0, 'CGI' => 0 }, ); CGI-Ajax-0.707/lib/0000755000175000017500000000000011073174173013730 5ustar bpedersebpederseCGI-Ajax-0.707/lib/CGI/0000755000175000017500000000000011073174173014332 5ustar bpedersebpederseCGI-Ajax-0.707/lib/CGI/Ajax.pm0000644000175000017500000012622211073174116015555 0ustar bpedersebpedersepackage CGI::Ajax; use strict; use Data::Dumper; use base qw(Class::Accessor); use overload '""' => 'show_javascript'; # for building web pages, so # you can just say: print $pjx BEGIN { use vars qw ($VERSION @ISA @METHODS); @METHODS = qw(url_list coderef_list CACHE DEBUG JSDEBUG html js_encode_function cgi_header_extra skip_header fname); CGI::Ajax->mk_accessors(@METHODS); $VERSION = .707; } ########################################### main pod documentation begin ## =head1 NAME CGI::Ajax - a perl-specific system for writing Asynchronous web applications =head1 SYNOPSIS use strict; use CGI; # or any other CGI:: form handler/decoder use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func ); print $pjx->build_html( $cgi, \&Show_HTML); sub perl_func { my $input = shift; # do something with $input my $output = $input . " was the input!"; return( $output ); } sub Show_HTML { my $html = < Enter something:
EOHTML return $html; } When you use CGI::Ajax within Applications that send their own header information, you can skip the header: my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func, 'skip_header' => 1, ); $pjx->skip_header(1); print $pjx->build_html( $cgi, \&Show_HTML); I =head1 DESCRIPTION CGI::Ajax is an object-oriented module that provides a unique mechanism for using perl code asynchronously from javascript- enhanced HTML pages. CGI::Ajax unburdens the user from having to write extensive javascript, except for associating an exported method with a document-defined event (such as onClick, onKeyUp, etc). CGI::Ajax also mixes well with HTML containing more complex javascript. CGI::Ajax supports methods that return single results or multiple results to the web page, and supports returning values to multiple DIV elements on the HTML page. Using CGI::Ajax, the URL for the HTTP GET/POST request is automatically generated based on HTML layout and events, and the page is then dynamically updated with the output from the perl function. Additionally, CGI::Ajax supports mapping URL's to a CGI::Ajax function name, so you can separate your code processing over multiple scripts. Other than using the Class::Accessor module to generate CGI::Ajax' accessor methods, CGI::Ajax is completely self-contained - it does not require you to install a larger package or a full Content Management System, etc. We have added I for other CGI handler/decoder modules, like L or L, but we can't test these since we run mod_perl2 only here. CGI::Ajax checks to see if a header() method is available to the CGI object, and then uses it. If method() isn't available, it creates it's own minimal header. A primary goal of CGI::Ajax is to keep the module streamlined and maximally flexible. We are trying to keep the generated javascript code to a minimum, but still provide users with a variety of methods for deploying CGI::Ajax. And VERY little user javascript. =head1 EXAMPLES The CGI::Ajax module allows a Perl subroutine to be called asynchronously, when triggered from a javascript event on the HTML page. To do this, the subroutine must be I, usually done during: my $pjx = new CGI::Ajax( 'JSFUNC' => \&PERLFUNC ); This maps a perl subroutine (PERLFUNC) to an automatically generated Javascript function (JSFUNC). Next you setup a trigger this function when an event occurs (e.g. "onClick"): onClick="JSFUNC(['source1','source2'], ['dest1','dest2']);" where 'source1', 'dest1', 'source2', 'dest2' are the DIV ids of HTML elements in your page...
L sends the values from source1 and source2 to your Perl subroutine and returns the results to dest1 and dest2. =head2 4 Usage Methods =over 4 =item 1 Standard CGI::Ajax example Start by defining a perl subroutine that you want available from javascript. In this case we'll define a subrouting that determines whether or not an input is odd, even, or not a number (NaN): use strict; use CGI::Ajax; use CGI; 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"); } Alternatively, we could have used coderefs to associate an exported name... my $evenodd_func = sub { # exactly the same as in the above subroutine }; Next we define a function to generate the web page - this can be done many 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. You can do this via a string containing the html, or from a coderef that returns the html, or from a function (as shown here)... sub Show_HTML { my $html = < CGI::Ajax Example Enter a number: 

EOT return $html; } The exported Perl subrouting is triggered using the C event handler of the input HTML element. The subroutine takes one value from the form, the input element B<'val1'>, and returns the the result to an HTML div element with an id of B<'resultdiv'>. Sending in the input id in an array format is required to support multiple inputs, and similarly, to output multiple the results, you can use an array for the output divs, but this isn't mandatory - as will be explained in the B usage. Now create a CGI object and a CGI::Ajax object, associating a reference to our subroutine with the name we want available to javascript. my $cgi = new CGI(); my $pjx = new CGI::Ajax( 'evenodd' => \&evenodd_func ); And if we used a coderef, it would look like this... my $pjx = new CGI::Ajax( 'evenodd' => $evenodd_func ); Now we're ready to print the output page; we send in the cgi object and the HTML-generating function. print $pjx->build_html($cgi,\&Show_HTML); CGI::Ajax has support for passing in extra HTML header information to the CGI object. This can be accomplished by adding a third argument to the build_html() call. The argument needs to be a hashref containing Key=>value pairs that CGI objects understand: print $pjx->build_html($cgi,\&Show_HTML, {-charset=>'UTF-8, -expires=>'-1d'}); See L for more header() method options. (CGI.pm, not the Perl6 CGI) That's it for the CGI::Ajax standard method. Let's look at something more advanced. =item 2 Advanced CGI::Ajax example Let's say we wanted to have a perl subroutine process multiple values from the HTML page, and similarly return multiple values back to distinct divs on the page. This is easy to do, and requires no changes to the perl code - you just create it as you would any perl subroutine that works with multiple input values and returns multiple values. The significant change happens in the event handler javascript in the HTML... onClick="exported_func(['input1','input2'],['result1','result2']);" Here we associate our javascript function ("exported_func") with two HTML element ids ('input1','input2'), and also send in two HTML element ids to place the results in ('result1','result2'). =item 3 Sending Perl Subroutine Output to a Javascript function Occassionally, you might want to have a custom javascript function process the returned information from your Perl subroutine. This is possible, and the only requierment is that you change your event handler code... onClick="exported_func(['input1'],[js_process_func]);" In this scenario, C is a javascript function you write to take the returned value from your Perl subroutine and process the results. I Beware that with this usage, B. If the exported Perl subroutine returns, e.g. 2 values, then C would need to process the input by working through an array, or using the javascript Function C object. function js_process_func() { var input1 = arguments[0] var input2 = arguments[1]; // do something and return results, or set HTML divs using // innerHTML document.getElementById('outputdiv').innerHTML = input1; } =item 4 URL/Outside Script CGI::Ajax example There are times when you may want a different script to return content to your page. This could be because you have an existing script already written to perform a particular task, or you want to distribute a part of your application to another script. This can be accomplished in L by using a URL in place of a locally-defined Perl subroutine. In this usage, you alter you creation of the L object to link an exported javascript function name to a local URL instead of a coderef or a subroutine. my $url = 'scripts/other_script.pl'; my $pjx = new CGI::Ajax( 'external' => $url ); This will work as before in terms of how it is called from you event handler: onClick="external(['input1','input2'],['resultdiv']);" The other_script.pl will get the values via a CGI object and accessing the 'args' key. The values of the B<'args'> key will be an array of everything that was sent into the script. my @input = $cgi->params('args'); $input[0]; # contains first argument $input[1]; # contains second argument, etc... This is good, but what if you need to send in arguments to the other script which are directly from the calling Perl script, i.e. you want a calling Perl script's variable to be sent, not the value from an HTML element on the page? This is possible using the following syntax: onClick="exported_func(['args__$input1','args__$input2'], ['resultdiv']);" Similary, if the external script required a constant as input (e.g. C, you would use this syntax: onClick="exported_func(['args__42'],['resultdiv']);" In both of the above examples, the result from the external script would get placed into the I element on our (the calling script's) page. If you are sending more than one argument from an external perl script back to a javascript function, you will need to split the string (AJAX applications communicate in strings only) on something. Internally, we use '__pjx__', and this string is checked for. If found, L will automatically split it. However, if you don't want to use '__pjx__', you can do it yourself: For example, from your Perl script, you would... return("A|B"); # join with "|" and then in the javascript function you would have something like... process_func() { var arr = arguments[0].split("|"); // arr[0] eq 'A' // arr[1] eq 'B' } In order to rename parameters, in case the outside script needs specifically-named parameters and not CGI::Ajax' I<'args'> default parameter name, change your event handler associated with an HTML event like this onClick="exported_func(['myname__$input1','myparam__$input2'], ['resultdiv']);" The URL generated would look like this... C You would then retrieve the input in the outside script with this... my $p1 = $cgi->params('myname'); my $p1 = $cgi->params('myparam'); Finally, what if we need to get a value from our HTML page and we want to send that value to an outside script but the outside script requires a named parameter different from I<'args'>? You can accomplish this with L using the getVal() javascript method (which returns an array, thus the C notation): onClick="exported_func(['myparam__' + getVal('div_id')[0]], ['resultdiv']);" This will get the value of our HTML element with and I of I, and submit it to the url attached to I. So if our exported handler referred to a URI called I'; return $rv; } ## new sub new { my ($class) = shift; my $self = bless( {}, ref($class) || $class ); # $self->SUPER::new(); $self->fname("fname");# default parameter for exported function name $self->JSDEBUG(0); # turn javascript debugging off (if on, # extra info will be added to the web page output # if set to 1, then the core js will get # compressed, but the user-defined functions will # not be compressed. If set to 2 (or anything # greater than 1 or 0), then none of the # javascript will get compressed. # $self->DEBUG(0); # turn debugging off (if on, check web logs) $self->CACHE(1); # default behavior is to allow cache of content # which can be explicitly switched off by passing # NO_CACHE in the arg list #accessorized attributes $self->coderef_list( {} ); $self->url_list( {} ); #$self->html(""); #$self->cgi(); #$self->cgi_header_extra(""); # set cgi_header_extra to an empty string # setup a default endcoding; if you need support for international # charsets, use 'escape' instead of encodeURIComponent. Due to the # number of browser problems users report about scripts with a default of # encodeURIComponent, we are setting the default to 'escape' $self->js_encode_function('escape'); if ( @_ < 2 ) { die "incorrect usage: must have fn=>code pairs in new\n"; } while (@_) { my ( $function_name, $code ) = splice( @_, 0, 2 ); if( $function_name eq 'skip_header' ){ $self->skip_header( $code ); next; } if ( ref($code) eq "CODE" ) { if ( $self->DEBUG() ) { print STDERR "name = $function_name, code = $code\n"; } # add the name/code to hash $self->coderef_list()->{$function_name} = $code; } elsif ( ref($code) ) { die "Unsuported code block/url\n"; } else { if ( $self->DEBUG() ) { print STDERR "Setting function $function_name to url $code\n"; } # if it's a url, it is added here $self->url_list()->{$function_name} = $code; } } return ($self); } ###################################################### ## METHODS - private ## ###################################################### # sub cgiobj(), cgi() # # Purpose: accessor method to associate a CGI object with our # CGI::Ajax object # Arguments: a CGI object # Returns: CGI::Ajax objects cgi object # Called By: originating cgi script, or build_html() # sub cgiobj { my $self = shift; # see if any values were sent in... if (@_) { my $cgi = shift; # add support for other CGI::* modules This requires that your web server # be configured properly. I can't test anything but a mod_perl2 # setup, so this prevents me from testing CGI::Lite,CGI::Simple, etc. if ( ref($cgi) =~ /CGI.*/ or ( $cgi->isa('CGI::Application') && $cgi->query =~ /CGI/ ) ) { #pmg if ( $self->DEBUG() ) { print STDERR "cgiobj() received a CGI-like object ($cgi)\n"; } $self->{'cgi'} = $cgi; } else { die "CGI::Ajax -- Can't set internal CGI object to a non-CGI object ($cgi)\n"; } } # return the object return ( $self->{'cgi'} ); } sub cgi { my $self = shift; if (@_) { return ( $self->cgiobj(@_) ); } else { return ( $self->cgiobj() ); } } ## # sub cgi_header_extra ## # ## # Purpose: accessor method to associate CGI header information ## # with the CGI::Ajax object ## # Arguments: a hashref with key=>value pairs that get handed off to ## # the CGI object's header() method ## # Returns: hashref of extra cgi header params ## # Called By: originating cgi script, or build_html() ## ## sub cgi_header_extra { ## my $self = shift; ## if ( @_ ) { ## $self->{'cgi_header_extra'} = shift; ## } ## return( $self->{'cgi_header_extra'} ); ## } # sub create_js_setRequestHeader # # Purpose: create text of the header for the javascript side, # xmlhttprequest call # Arguments: none # Returns: text of header to pass to xmlhttpreq call so it will # match whatever was setup for the main web-page # Called By: originating cgi script, or build_html() # sub create_js_setRequestHeader { my $self = shift; my $cgi_header_extra = $self->cgi_header_extra(); my $js_header_string = q{r.setRequestHeader("}; #$js_header_string .= $self->cgi()->header( $cgi_header_extra ); $js_header_string .= $self->getHeader; $js_header_string .= q{");}; #if ( ref $cgi_header_extra eq "HASH" ) { # foreach my $k ( keys(%$cgi_header_extra) ) { # $js_header_string .= $self->cgi()->header($cgi_headers) # } #} else { #print STDERR $self->cgi()->header($cgi_headers) ; if ( $self->DEBUG() ) { print STDERR "js_header_string is (", $js_header_string, ")\n"; } return ($js_header_string); } # sub show_common_js() # # Purpose: create text of the javascript needed to interface with # the perl functions # Arguments: none # Returns: text of common javascript subroutine, 'do_http_request' # Called By: originating cgi script, or build_html() # sub show_common_js { my $self = shift; my $fname = $self->fname(); my $encodefn = $self->js_encode_function(); my $decodefn = $encodefn; $decodefn =~ s/^(en)/de/; $decodefn =~ s/^(esc)/unesc/; #my $request_header_str = $self->create_js_setRequestHeader(); my $request_header_str = ""; my $rv = <
";
    for( var i=0; i < ajax.length; i++ ) {
      tmp += '' +
      decodeURI(ajax[i].url) + ' <' + '/a>
'; } document.getElementById('pjxdebugrequest').innerHTML = tmp + "<" + "/pre>"; } EOT if ( $self->JSDEBUG() <= 1 ) { $rv = $self->compress_js($rv); } return ($rv); } # sub compress_js() # # Purpose: searches the javascript for newlines and spaces and # removes them (if a newline) or shrinks them to a single (if # space). # Arguments: javascript to compress # Returns: compressed js string # Called By: show_common_js(), # sub compress_js { my ( $self, $js ) = @_; return if not defined $js; return if $js eq ""; $js =~ s/\n//g; # drop newlines $js =~ s/\s+/ /g; # replace 1+ spaces with just one space return $js; } # sub insert_js_in_head() # # Purpose: searches the html value in the CGI::Ajax object and inserts # the ajax javascript code in the section, # or if no such section exists, then it creates it. If # JSDEBUG is set, then an extra div will be added and the # url will be displayed as a link # Arguments: none # Returns: none # Called By: build_html() # sub insert_js_in_head { my $self = shift; my $mhtml = $self->html(); my $newhtml; my @shtml; my $js = $self->show_javascript(); if ( $self->JSDEBUG() ) { my $showurl = qq!

!; # find the terminal so we can insert just before it my @splith = $mhtml =~ /(.*)(<\s*\/\s*body[^>]*>?)(.*)/is; $mhtml = $splith[0] . $showurl . $splith[1] . $splith[2]; } # see if we can match on @shtml = $mhtml =~ /(.*)(<\s*head[^>]*>?)(.*)/is; if (@shtml) { # yes, there's already a , so let's insert inside it, # at the beginning $newhtml = $shtml[0] . $shtml[1] . $js . $shtml[2]; } elsif ( @shtml = $mhtml =~ /(.*)(<\s*html[^>]*>?)(.*)/is ) { # there's no , so look for the tag, and insert out # javascript inside that tag $newhtml = $shtml[0] . $shtml[1] . $js . $shtml[2]; } else { $newhtml .= ""; $newhtml .= $js; $newhtml .= ""; $newhtml .= "No head/html tags, nowhere to insert. Returning javascript anyway
"; $newhtml .= ""; } $self->html($newhtml); return; } # sub handle_request() # # Purpose: makes sure a fname function name was set in the CGI # object, and then tries to eval the function with # parameters sent in on args # Arguments: none # Returns: the result of the perl subroutine, as text; if multiple # arguments are sent back from the defined, exported perl # method, then join then with a connector (__pjx__). # Called By: build_html() # sub handle_request { my ($self) = shift; my $result; # $result takes the output of the function, if it's an # array split on __pjx__ my @other = (); # array for catching extra parameters # we need to access "fname" in the form from the web page, so make # sure there is a CGI object defined return undef unless defined $self->cgi(); my $rv = $self->getHeader( $self->cgi_header_extra() ); if ( !defined $rv and $self->skip_header == 0 ) { # don't have an object with a "header()" method, so just create # a mimimal one $rv = "Content-Type: text/html;"; # TODO: $rv .= $self->cgi_header_extra(); $rv .= "\n\n"; } # get the name of the function my $func_name = $self->getparam($self->fname()); #pmg # check if the function name was created if ( defined $self->coderef_list()->{$func_name} ) { my $code = $self->coderef_list()->{$func_name}; # eval the code from the coderef, and append the output to $rv if ( ref($code) eq "CODE" ) { my @args = $self->getparam("args"); #pmg eval { ( $result, @other ) = $code->(@args) }; #pmg if ($@) { # see if the eval caused and error and report it # Should we be more severe and die? print STDERR "Problem with code: $@\n"; } if (@other) { $rv .= join( "__pjx__", ( $result, @other ) ); if ( $self->DEBUG() ) { print STDERR "rv = $rv\n"; } } else { if ( defined $result ) { $rv .= $result; } } } # end if ref = CODE } else { # # problems with the URL, return a CGI rrror print STDERR "POSSIBLE SECURITY INCIDENT! Browser from ", $self->remoteaddr(); print STDERR "\trequested URL: ", $self->geturl(); print STDERR "\tfname request: ", $self->getparam($self->fname()); print STDERR " -- returning Bad Request status 400\n"; my $header = $self->getHeader( -status => '400' ); if ( !defined $header ) { # don't have an object with a "header()" method, so just create # a mimimal one with 400 error $rv = "Status: 400\nContent-Type: text/html;\n\n"; } } return $rv; } # sub make_function() # # Purpose: creates the javascript wrapper for the underlying perl # subroutine # Arguments: CGI object from web form, and the name of the perl # function to export to javascript, or a url if the # function name refers to another cgi script # Returns: text of the javascript-wrapped perl subroutine # Called By: show_javascript; called once for each registered perl # subroutine # sub make_function { my ( $self, $func_name ) = @_; return ("") if not defined $func_name; return ("") if $func_name eq ""; my $rv = ""; my $script = $0 || $ENV{SCRIPT_FILENAME}; $script =~ s/.*[\/|\\](.+)$/$1/; my $outside_url = $self->url_list()->{$func_name}; my $url = defined $outside_url ? $outside_url : $script; if ( $url =~ /\?/ ) { $url .= '&'; } else { $url .= '?' } $url = "'$url'"; my $jsdebug = ""; if ( $self->JSDEBUG() ) { $jsdebug = "jsdebug()"; } my $cache = $self->CACHE(); #create the javascript text $rv .= <. =head1 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. =head1 SEE ALSO L L L =cut 1; __END__ CGI-Ajax-0.707/scripts/0000755000175000017500000000000011073174173014651 5ustar bpedersebpederseCGI-Ajax-0.707/scripts/pjx_combo.pl0000755000175000017500000001126711053027714017174 0ustar bpedersebpederse#! /usr/bin/perl -w # CGI-Ajax: example script 'pjx_combo.pl' # # INSTALL: place in an apache location that can execute perl scripts # # this script demonstrates a set of dynamic select boxes, where the # selection in a box changes other select box contents, or html div # values. The data in each select box comes from the data anonymous # hash, but could just as easily come from a database connection, etc. # # N.B. this requires CGI__Ajax version >=0.49 # # Also, this example has lots of stderr output, so follow your apache # log files to see what's going on. # use strict; use CGI::Ajax 0.49; use CGI; use vars qw( $data ); # This is our data - top level keys get put in the leftmost select # box, next level of keys get the second select box. Values will end # up in the resultdiv html element $data = { 'A' => { '1' => "A1", '2' => "A2", '3' => "A3", '42' => "A42" }, 'B' => { 'green' => "Bgreen", 'red' => "Bred" }, 'something' => { 'firefly' => "great show" }, 'final_thing' => { 'email' => "chunkeylover53", 'name' => "homer", 'address' => "742 Evergreen Terrace" } }; my $q = new CGI; # need a new CGI object # compose our list of functions to export to js my %hash = ( 'SetA' => \&set_listA, 'SetB' => \&set_listB, 'ShowResult' => \&show_result ); my $pjx = CGI::Ajax->new( %hash ); # this is our CGI::Ajax object $pjx->js_encode_function('encodeURIComponent'); $pjx->DEBUG(1); # turn on debugging $pjx->JSDEBUG(1); # turn on javascript debugging, which will place a # new div element at the bottom of our page showing # the asynchrously requested URL print $pjx->build_html( $q, \&Show_HTML ); # this builds our html # page, inserting js # This subroutine is responsible for outputting the HTML of the web # page. Note that I've added an additional javascript function to # erase/reset contents. This prevents strange effects from # overwriting a div without clearing it out first. sub Show_HTML { my $html = < Combo Example
EOT return($html); } # these are my exported functions - note that set_listA and set_listB # are just returning html to be inserted into their respective div # elements. sub set_listA { # this is the returned text... html to be displayed in the div # defined in the javascript call my $txt = qq!"; print STDERR "set_listA:\n"; print STDERR "returning $txt\n"; return($txt); } sub set_listB { my $listA_selection = shift; print STDERR "set_listB: received $listA_selection .\n"; # this is the returned text... html to be displayed in the div # defined in the javascript call my $txt = qq!"; print STDERR "set_listB:\n"; print STDERR "returning $txt\n"; return($txt); } sub show_result { my $listA_selection = shift; my $txt = ""; # this loop is needed in case the user selected multiple elements in # the second select box, listB while ( @_ ) { my $in = shift; $txt .= $data->{ $listA_selection }->{ $in } . "
"; } print STDERR "show_result - returning txt with value: $txt\n"; return( $txt ); } CGI-Ajax-0.707/scripts/pjx_url.pl0000755000175000017500000000171311053027714016672 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use URLs to define # your CGI::Ajax functions. use strict; use CGI::Ajax; use CGI; my $q = new CGI; # the format here implies that 'convert_degrees.pl' is at the same # level in the web server's document root as this script. my $pjx = CGI::Ajax->new( 'myfunc' => 'convert_degrees.pl'); $pjx->JSDEBUG(1); my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Outside URL Example Degrees Centigrade: 
Degrees Kelvin:  EOT return $html; }; print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_formDump.pl0000755000175000017500000000246011053027714017661 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $concatter = sub { my $str = "All Values Are
\n"; map { $str .= ' and ' . $_ } @_; print STDERR $str; return $str; }; my $Show_Form = sub { my $html = ""; $html = < CGI::Ajax Multiple Return Value Example










EOT ; return $html; }; my $pjx = CGI::Ajax->new( 'jsFunc' => $concatter); $pjx->JSDEBUG(2); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_splitargs.pl0000755000175000017500000000225311053027714020100 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions, and the methods return multiple results to # the page # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $divide = sub { my $a = shift; my $b = shift; return ($a / $b,"this is 2nd return value"); }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Multiple Return Value Example
Enter Number:
EOT return $html; }; my $pjx = CGI::Ajax->new('divide' => $divide); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/CGI-Application-Ajax-ex01.pl0000755000175000017500000000164211053027714021507 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; package main ; my $tester = new Tester ; $tester->run ; package Tester ; use base qw(CGI::Application); use CGI::Ajax; sub setup { my $self = shift; $self->run_modes([qw( start )]); } sub Show_HTML { my $html = < CGI::Ajax Example
Enter Something: 
Enter Something: 
EOT } sub calc { my $input = shift; return "got input: $input " ; } sub start { my $self = shift; my $pjx = new CGI::Ajax( 'jsfunc' => \&calc ); $pjx->JSDEBUG(2); my $text = $pjx->build_html($self,\&Show_HTML ); return $text ; } CGI-Ajax-0.707/scripts/pjx_JSON.pl0000755000175000017500000000225311053027714016641 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax JSON Example

Get The Letter Following the One you Enter

Enter Number:

The JavaScript Object:

After Parsing (use eval)
EOT return $html; }; my $pjx = CGI::Ajax->new('json' => 'pjx_JSON_out.pl'); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/CGI-Application-Ajax-ex03.pl0000755000175000017500000000341511053027714021511 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; package main ; my $tester = new Tester ; $tester->run ; package Tester ; use base qw(CGI::Application); use CGI::Ajax; sub setup { my $self = shift; $self->run_modes([qw( start )]); } # define an anonymous perl subroutine that you want available to # javascript on the generated web page. # 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 = ""; $html .= < CGI::Ajax Example
Enter a number: 

EOT return $html; } sub start { my $self = shift; my $evenodd_func = sub { my $input = shift; my $magic = "      look ma, no submit!
"; # see if input is defined if ( not defined $input ) { return("input not defined or NaN" . $magic); } # see if value is a number (*thanks Randall!*) if ( $input !~ /\A\d+\z/ ) { return("input is NaN" . $magic); } # got a number, so mod by 2 $input % 2 == 0 ? return("$input is EVEN" . $magic) : return("$input is ODD" . $magic); }; # don't forget the trailing ';', since this is an anon subroutine my $pjx = new CGI::Ajax( 'evenodd' => $evenodd_func ); $pjx->JSDEBUG(2); my $text = $pjx->build_html($self,\&Show_HTML); # this outputs the html for the page return $text ; } CGI-Ajax-0.707/scripts/pjx_objects_2_url.pl0000755000175000017500000000243711053027714020630 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions. # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $exported_fx = sub { my $value_a = shift; my $iq = new CGI; my $a = $q->param('a'); my $b = $q->param('b'); my $test = $q->param('test'); return( 'entered value was: ' . $value_a . '
a was: ' . $a . "..." . '
b was: ' . $b . "..." . '
test was: ' . $test . "..." ); }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Example
this javascript object is sent in as an argument: {'a':123,'b':345,'test':'123 Evergreen Terrace'}

Enter something else: 

EOT return $html; }; my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); $pjx->JSDEBUG(2); $pjx->DEBUG(2); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/CGI-Application-Ajax-ex02.pl0000755000175000017500000000176711053027714021520 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; Same as ex1 except that data is sent only when the mouse is moved out of the field package main ; my $tester = new Tester ; $tester->run ; package Tester ; use base qw(CGI::Application); use CGI::Ajax; sub setup { my $self = shift; $self->run_modes([qw( start )]); } sub Show_HTML { my $html = < CGI::Ajax Example
Enter Something: 
Enter Something: 
EOT } sub calc { my $input = shift; return "got input: $input " ; } sub start { my $self = shift; my $pjx = new CGI::Ajax( 'jsfunc' => \&calc ); $pjx->JSDEBUG(2); my $text = $pjx->build_html($self,\&Show_HTML ); return $text ; } CGI-Ajax-0.707/scripts/pjx_callback.pl0000755000175000017500000000254611053027714017631 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions, and the methods return multiple results to # the page # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $multiply = sub { my $a = shift; my $b = shift; return $a * $b; }; my $divide = sub { my $a = shift; my $b = shift; return $a / $b; }; my $G = 'asdf'; my $Show_Form = sub { my $html = ""; $html .= qq! CGI::Ajax Multiple Return Value Example
Enter Number:
URL FROM "this" in callback:
!; return $html; }; my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_radio.pl0000755000175000017500000000245111053027714017166 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax 0.57; use CGI; my $q = new CGI; # need a new CGI object # compose our list of functions to export to js my %hash = ( 'myFunc' => \&perl_func,); my $pjx = CGI::Ajax->new( %hash ); # this is our CGI::Ajax object $pjx->DEBUG(1); # turn on debugging $pjx->JSDEBUG(1); # turn on javascript debugging, which will place a # new div element at the bottom of our page showing # the asynchrously requested URL print $pjx->build_html( $q, \&Show_HTML ); # this builds our html # page, inserting js # This subroutine is responsible for outputting the HTML of the web # page. sub Show_HTML { my $html = < Radio Example
red blue yellow green
EOT return($html); } # this is the exported function sub perl_func { $a = shift; return $a . " was selected"; } CGI-Ajax-0.707/scripts/pjx_manyret.pl0000755000175000017500000000410211053027714017542 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions, and the methods return multiple results to # the page # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $exported_fx = sub { my $value_a = shift; my $value_b = shift; $value_a = "" if not defined $value_a; # make sure there's def $value_b = "" if not defined $value_b; # make sure there's def if ( $value_a =~ /\D+/ or $value_a eq "" ) { return( $value_a, $value_b, 'NaN' ); } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { return( $value_a, $value_b, 'NaN' ); } else { # got two numbers, so lets multiply them together return( $value_a, $value_b, $value_a * $value_b ); } }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Multiple Return Value Example
Enter something: 
Enter something else: 

Input A Input B Result
EOT return $html; }; my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); $pjx->JSDEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_checkbox.pl0000755000175000017500000000124511053027714017656 0ustar bpedersebpederse#!/usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $perl_func = sub { my $input = shift; print "got $input"; }; sub Show_HTML { my $html = ""; $html .= < CGI::Ajax Example
val1
EOT return $html; } my $cgi = new CGI(); # create a new CGI object my $pjx = new CGI::Ajax( 'jsFunc' => $perl_func ); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($cgi,\&Show_HTML); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_podex.pl0000755000175000017500000000351311053027714017207 0ustar bpedersebpederse#!/usr/bin/perl -w use strict; use CGI::Ajax; use CGI; # define an anonymous perl subroutine that you want available to # javascript on the generated web page. my $evenodd_func = sub { my $input = shift; my $magic = "      look ma, no submit!
"; # see if input is defined if ( not defined $input ) { return("input not defined or NaN" . $magic); } # see if value is a number (*thanks Randall!*) if ( $input !~ /\A\d+\z/ ) { return("input is NaN" . $magic); } # got a number, so mod by 2 $input % 2 == 0 ? return("$input is EVEN" . $magic) : return("$input is ODD" . $magic); }; # don't forget the trailing ';', since this is an anon subroutine # 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 = ""; $html .= < CGI::Ajax Example Enter a number: 

EOT return $html; } my $cgi = new CGI(); # create a new CGI object # now we create a CGI::Ajax object, and associate our anon code my $pjx = new CGI::Ajax( 'evenodd' => $evenodd_func ); # now print the page. This can be done easily using # CGI::Ajax->build_html, sending in the CGI object to generate the html # header. This could also be done manually, and then you don't need # the build_html() method print $pjx->build_html($cgi,\&Show_HTML); # this outputs the html for the page # that's it! CGI-Ajax-0.707/scripts/pjx_JSON_out.pl0000755000175000017500000000043611053030256017524 0ustar bpedersebpederse#!/usr/bin/perl -w use strict; use CGI; use JSON; use Data::Dumper; my $q = new CGI; print $q->header(); my $val = $q->param('args'); my @vals = split(//, $val); my $hash; map { $hash->{$_} = chr(ord($_)+1) } @vals; my $json = objToJson($hash); print "var jsonObj = $json"; CGI-Ajax-0.707/scripts/pjx_cr.pl0000755000175000017500000000267411053027714016503 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example script of how you would use coderefs to define # your CGI::Ajax functions. # # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $exported_fx = sub { my $value_a = shift; my $value_b = shift; $value_a = "" if not defined $value_a; # make sure there's def $value_b = "" if not defined $value_b; # make sure there's def if ( $value_a =~ /\D+/ or $value_a eq "" ) { return( $value_a . " and " . $value_b ); } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { return( $value_a . " and " . $value_b ); } else { # got two numbers, so lets multiply them together return( $value_a * $value_b ); } }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Example
Enter something: 
Enter something else: 

EOT return $html; }; my $pjx = CGI::Ajax->new( 'myfunc' => $exported_fx); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_dynselect.pl0000755000175000017500000000637511053027714020073 0ustar bpedersebpederse#! /usr/bin/perl -w # dynamic select boxes, using a db use strict; use CGI::Ajax; use CGI; use DBI; my $q = new CGI; ### phone book database # CREATE TABLE `phonebook` ( # `login` varchar(10) NOT NULL, # `fullname` varchar(200) NOT NULL, # `areacode` int(10) unsigned NOT NULL default '123', # `phone` varchar(7) NOT NULL # ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Users and phone numbers'; # my $exported_fx = sub { my $searchterm = shift; my $sql = qq< select login from phonebook where login like ? or fullname like ? >; my $dbh = DBI->connect('dbi:mysql:test:localhost','guestuser','guestp4ss'); my $sth = $dbh->prepare( $sql ); $sth->execute( $searchterm . '%', $searchterm . '%' ); # start off the div contents with select init my $html = qq!\n!; return($html); }; my $get_details = sub { my $login = shift; my $sql = qq< select * from phonebook where login = ? >; my $dbh = DBI->connect('dbi:mysql:test:localhost','guestuser','guestp4ss'); my $sth = $dbh->prepare( $sql ); $sth->execute( $login ); my $html = ""; my $row = $sth->fetch(); if ( defined $row ) { $html .= "Login: " . $row->[0] . "
"; $html .= "Full Name: " . $row->[1] . "
"; $html .= "Area Code: " . $row->[2] . "
"; $html .= "Phone: " . $row->[3] . "
"; } else { $html .= "No Such User $login\n"; } return($html); }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Example Who are you searching for?
Start typing and matches will display in the select box.
Selecting a match will give you details. 

EOT $html .= dump_table(); $html .= <

Show Source
EOT return $html; }; sub dump_table { my $sql = qq< select login from phonebook >; my $dbh = DBI->connect('dbi:mysql:test:localhost','guestuser','guestp4ss'); my $sth = $dbh->prepare( $sql ); $sth->execute(); my $html = ""; while ( my $row = $sth->fetch() ) { $html .= ""; } $html .= "
Current Logins in DB
" . $row->[0] . "
"; return($html); } my $pjx = CGI::Ajax->new( search => $exported_fx, details => $get_details ); $pjx->JSDEBUG(1); $pjx->DEBUG(1); # not show the html, which will include the embedded javascript code # to handle the ajax interaction print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_loading.pl0000755000175000017500000000331711053027714017507 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $func = sub { my $input = shift; my $i=6000000; while($i--){ } return "got input: $input " . 'done'; }; sub Show_HTML { my $html = < CGI::Ajax Example
Enter Something: 
Enter Something: 

EOT } my $cgi = new CGI(); # create a new CGI object my $pjx = new CGI::Ajax( 'jsfunc' => $func ); print $pjx->build_html($cgi,\&Show_HTML); CGI-Ajax-0.707/scripts/pjx_chained.pl0000755000175000017500000000215511053027714017464 0ustar bpedersebpederse#! /usr/bin/perl -w # pjx_chained.pl: Multiple exported perl subs, and the exported # functions are chained to an event, like this... # onclick="func1(['in1'],['out1']); func2(['in1'],['out2']);" use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $multiply = sub { my $a = shift; my $b = shift; return $a * $b; }; my $divide = sub { my $a = shift; my $b = shift; return $a / $b; }; my $Show_Form = sub { my $html = ""; $html .= < CGI::Ajax Chained function Example
Enter Number:

EOT return $html; }; my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/convert_degrees.pl0000644000175000017500000000171111053027714020360 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header(); if ( defined $q->param('submit') or defined $q->param('Centigrade') or defined $q->param('Kelvin')) { my $result = ""; if ( defined $q->param('Centigrade') and $q->param('Centigrade') ne "") { $result = $q->param('Centigrade') + 273.15; } elsif ( defined $q->param('Kelvin') and $q->param('Kelvin') ne "" ) { $result = $q->param('Kelvin') - 273.15; } print $result; } else { print &Show_Form(); print &Show_Footer(); } sub Show_Form { my $html = ""; $html .= < Temperature Conversion
Temperature =
degrees C
degrees K

EOT return $html; } sub Show_Footer { print "\n"; return; } CGI-Ajax-0.707/scripts/pjx_change_encoding.pl0000755000175000017500000000154511053027714021166 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $func = sub { my $input = shift; return "got input: $input " ; }; sub Show_HTML { my $html = < CGI::Ajax Example
Enter Something: 
Enter Something: 
EOT } my $cgi = new CGI(); # create a new CGI object my $pjx = new CGI::Ajax( 'jsfunc' => $func ); # the default encoding for CGI::Ajax is encodeURIComponent; # if this causes problems, you can use escape or your own javascript # function; $pjx->js_encode_function('escape'); print $pjx->build_html($cgi,\&Show_HTML); CGI-Ajax-0.707/scripts/pjx_NO_CACHE_callee.pl0000755000175000017500000000035711053027714020577 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header(); my ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); printf "%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec; CGI-Ajax-0.707/scripts/pjx_NO_CACHE_caller.pl0000755000175000017500000000222711053027714020612 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an script calls an external script and avoids caching: # NB The CGI::Ajax object must come AFTER the coderefs are declared. use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $Show_Form = sub { my $html = ""; $html .= <CGI::Ajax No_Cache Example If the same URL is requested, A browser may cache the result and return it without querying the requested URL. To avoid that, use the 'NO_CACHE' keyword as a parameter in your javascript function.
Click the button and a perl script 'pjx_NO_CACHE_callee.pl should return the current time:



New Time:
EOT return $html; }; my $pjx = CGI::Ajax->new( 'perl_script' => 'pjx_NO_CACHE_callee.pl'); $pjx->JSDEBUG(1); $pjx->DEBUG(1); print $pjx->build_html($q,$Show_Form); # this outputs the html for the page CGI-Ajax-0.707/scripts/pjx_subs.pl0000755000175000017500000000265611053027714017053 0ustar bpedersebpederse#! /usr/bin/perl -w # this is an example of using subs (not coderefs) for your perljax # functions # # NB The CGI::Ajax object DOES NOT need to follow the function # declarations, as it does in the coderef example use strict; use CGI::Ajax; use CGI; my $q = new CGI; my $pjx = CGI::Ajax->new( 'myfunc' => \&exported_fx); print $pjx->build_html($q,\&Show_Form); # this outputs the html for the page sub exported_fx { my $value_a = shift; my $value_b = shift; $value_a = "" if not defined $value_a; # make sure there's def $value_b = "" if not defined $value_b; # make sure there's def if ( $value_a =~ /\D+/ or $value_a eq "" ) { return( $value_a . " and " . $value_b ); } elsif ( $value_b =~ /\D+/ or $value_b eq "" ) { return( $value_a . " and " . $value_b ); } else { # got two numbers, so lets multiply them together return( $value_a * $value_b ); } } sub Show_Form { my $html = ""; $html .= < CGI::Ajax Example
Enter something: 
Enter something else: 

EOT return $html; } CGI-Ajax-0.707/scripts/pjx_change_headers.pl0000755000175000017500000000141211053027714021004 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; use CGI; my $func = sub { my $input = shift; return "got input: $input " ; }; sub Show_HTML { my $html = < CGI::Ajax Example
Enter Something: 
Enter Something: 
EOT } my $cgi = new CGI(); # create a new CGI object my $pjx = new CGI::Ajax( 'jsfunc' => $func ); # the send in some extra headers; print $pjx->build_html($cgi,\&Show_HTML, { '-expires' => '1d', '-charset' => 'ISO-8859-1'} ); CGI-Ajax-0.707/scripts/pjx_from_span.pl0000755000175000017500000000231511053027714020053 0ustar bpedersebpederse#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $cgi= CGI->new; my $a= CGI::Ajax->new( 'test_elt_html' => \&test_elt_html ); $a->DEBUG(2); $a->JSDEBUG(2); print $a->build_html( $cgi, \&html_page); sub html_page { return <
test with div

test with span

test with p

some stuff

EOH ; } sub test_elt_html { my( $elt_html)= @_; print STDERR "IN:" . $elt_html , "\n"; return $elt_html; } CGI-Ajax-0.707/scripts/pjx_nobuild.pl0000755000175000017500000000132711053027714017525 0ustar bpedersebpederse#! /usr/bin/perl -w use strict; use CGI::Ajax; my $my_func = sub { my $arg = shift; return ( $arg . " with some extra" ); }; my $pjx = new CGI::Ajax( 'tester' => $my_func ); $pjx->JSDEBUG(1); $pjx->DEBUG(1); use CGI; my $cgi = new CGI(); print $cgi->header(); $pjx->cgi( $cgi ); my $html = ""; $html .= ""; $html .= ""; $html .= $pjx; $html .= <



EOT if ( not $cgi->param('fname') ) { print $html; } else { print $pjx->handle_request(); } CGI-Ajax-0.707/t/0000755000175000017500000000000011073174173013425 5ustar bpedersebpederseCGI-Ajax-0.707/t/002_load.t0000644000175000017500000000034011053027713015102 0ustar bpedersebpederse# -*- perl -*- # t/002_load.t - check module loading and create testing directory use Test::More tests => 2; BEGIN { use_ok( 'CGI::Ajax' ); } my $object = CGI::Ajax->new ( 'myfunc' => ''); isa_ok ($object, 'CGI::Ajax'); CGI-Ajax-0.707/t/001_load.t0000644000175000017500000000022611053027713015104 0ustar bpedersebpederse# -*- perl -*- # t/001_load.t - check to see if Class::Acceccor module is avail use Test::More tests => 1; BEGIN { use_ok( 'Class::Accessor' ); }