From a82451eefa47668fc17b22e7365e390483ff3296 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 18 Nov 2011 17:10:11 +0100 Subject: [PATCH] CGI::Ajax entfernt. --- SL/Form.pm | 1 - SL/InstallationCheck.pm | 1 - bin/mozilla/invoice_io.pl | 1 - bin/mozilla/io.pl | 1 - doc/INSTALL.html | 4 - doc/INSTALL.texi | 5 - doc/INSTALL.txt | 5 - doc/Lx-Office_Installation_DE.pdf | Bin 159398 -> 159244 bytes modules/override/CGI/.htaccess | 2 - modules/override/CGI/Ajax.pm | 1217 ----------------------------- 10 files changed, 1237 deletions(-) delete mode 100644 modules/override/CGI/.htaccess delete mode 100644 modules/override/CGI/Ajax.pm diff --git a/SL/Form.pm b/SL/Form.pm index 15d66cec9..37e4a21b6 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -40,7 +40,6 @@ package Form; use Data::Dumper; use CGI; -use CGI::Ajax; use Cwd; use Encode; use File::Copy; diff --git a/SL/InstallationCheck.pm b/SL/InstallationCheck.pm index 6311d2b0c..3a5ffe429 100644 --- a/SL/InstallationCheck.pm +++ b/SL/InstallationCheck.pm @@ -13,7 +13,6 @@ BEGIN { { name => "Archive::Zip", version => '1.16', url => "http://search.cpan.org/~adamk/", debian => 'libarchive-zip-perl' }, { name => "Class::Accessor", version => '0.30', url => "http://search.cpan.org/~kasei/", debian => 'libclass-accessor-perl' }, { name => "Config::Std", url => "http://search.cpan.org/~dconway/", debian => 'libconfig-std-perl' }, - { name => "CGI::Ajax", version => '0.697', url => "http://search.cpan.org/~bct/" }, # no debian package, ours contains bugfixes { name => "DateTime", url => "http://search.cpan.org/~drolsky/", debian => 'libdatetime-perl' }, { name => "DBI", version => '1.50', url => "http://search.cpan.org/~timb/", debian => 'libdbi-perl' }, { name => "DBD::Pg", version => '1.49', url => "http://search.cpan.org/~dbdpg/", debian => 'libdbd-pg' }, diff --git a/bin/mozilla/invoice_io.pl b/bin/mozilla/invoice_io.pl index c8097e325..42e402ec8 100644 --- a/bin/mozilla/invoice_io.pl +++ b/bin/mozilla/invoice_io.pl @@ -34,7 +34,6 @@ ####################################################################### use CGI; -use CGI::Ajax; use List::Util qw(max); use SL::Common; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index c569ef8a5..59b594aac 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -38,7 +38,6 @@ use Carp; use CGI; -use CGI::Ajax; use List::Util qw(min max first); use SL::CVar; diff --git a/doc/INSTALL.html b/doc/INSTALL.html index a6a05f129..482115847 100644 --- a/doc/INSTALL.html +++ b/doc/INSTALL.html @@ -215,7 +215,6 @@ einer Standard-Perl-Installation sind:
  • parent
  • Archive::Zip
  • Class::Accessor -
  • CGI::Ajax
  • Config::Std
  • DateTime
  • DBI @@ -248,9 +247,6 @@ in 2.6.1 weiterhin mit ausgeliefert, wurden in einer zukünftigen Version aber aus dem Paket entfernt werden. Es wird empfohlen diese Module zusammen mit den anderen als Bibliotheken zu installieren. -

    CGI::Ajax ist nach wie vor in einer modifizierten Version mitgeliefert -und braucht nicht nachinstalliert werden. -

    Die zu installierenden Pakete können in den verschiedenen Distributionen unterschiedlich heißen.

    Für Debian oder Ubuntu benötigen Sie diese Pakete: diff --git a/doc/INSTALL.texi b/doc/INSTALL.texi index b158125c5..b14f96435 100644 --- a/doc/INSTALL.texi +++ b/doc/INSTALL.texi @@ -140,8 +140,6 @@ Archive::Zip @item Class::Accessor @item -CGI::Ajax -@item Config::Std @item DateTime @@ -190,9 +188,6 @@ in 2.6.1 weiterhin mit ausgeliefert, wurden in einer zukünftigen Version aber aus dem Paket entfernt werden. Es wird empfohlen diese Module zusammen mit den anderen als Bibliotheken zu installieren. -@code{CGI::Ajax} ist nach wie vor in einer modifizierten Version mitgeliefert -und braucht nicht nachinstalliert werden. - Die zu installierenden Pakete können in den verschiedenen Distributionen unterschiedlich heißen. Für Debian oder Ubuntu benötigen Sie diese Pakete: diff --git a/doc/INSTALL.txt b/doc/INSTALL.txt index 18a666210..7a9e99304 100644 --- a/doc/INSTALL.txt +++ b/doc/INSTALL.txt @@ -133,8 +133,6 @@ Bestandteil einer Standard-Perl-Installation sind: * Class::Accessor - * CGI::Ajax - * Config::Std * DateTime @@ -183,9 +181,6 @@ zukünftigen Version aber aus dem Paket entfernt werden. Es wird empfohlen diese Module zusammen mit den anderen als Bibliotheken zu installieren. - `CGI::Ajax' ist nach wie vor in einer modifizierten Version -mitgeliefert und braucht nicht nachinstalliert werden. - Die zu installierenden Pakete können in den verschiedenen Distributionen unterschiedlich heißen. diff --git a/doc/Lx-Office_Installation_DE.pdf b/doc/Lx-Office_Installation_DE.pdf index 2920946cabd171759b55f13c3c7cdf630bb2024f..0c469927e354582d7ef11a8e437b63ed742d2a74 100644 GIT binary patch delta 5527 zcmai0c|4Wt7CyG3gcEXU*e8Xeq;DRG>e7Jd5|8TMGl)>$vmL@m1+^&2vIBE4_c(M!s5ZQgC zGn*IkL2vszjn7`CZ5gqi$qknZ+k@*53!m(4C=?Y>9B!?dZaeHbgZj-rAMqa#dsb)g z!*aewEcRZoEO_;%yQQl>g#Dp>?QS=ZaT@*}*&nIW*)pguo)!`tGe=3P2hme?r0gd@!xrK650wmEMRbnI_BXN#YXj^x??jfTZ(5TjTtTB(i2* z%?Z_-U*%|WN(+sv-*}%c^sBw_*)X2Sa;jWe^<{WcQFxjt+_GG!S&_;9lA3S7f1P}m zM5pvX_yo;8wULt*p(VNo8Oie0ExB9v0dB=t!b{V(9Gubk{#)O%*DhNc(=K;gsZ_4M zFR8!%y}!+-d3Vlf^(Y_6;fGd|^RWv_**X(^JJtGSg{pm$T@jfQO^K)Wwmyv?cU;XN zxpa#D?VIp$&Ti2On`NH_8)sbBz3dRU>qwn-;l9%4Y6k<=`>$o9a(cfiCgrb>bF+^O zFxHUsd$_1rxO--lamh;2VBOXCUCOIr`DB%_6!okezD8Jb@IceK>I#FE+A_|Q;(5=J z)z>4I)>zo+@>-hRN<1H*j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7$Vz21S1hvL;ylUoIp?*MA-UJ z1jc@pr6bpfE}DV@00Gj4Yea3tNED;Tg&za~(bjIl4}hS5a}y;MahMevh>$o0(1R09 zb}kquO2YK7?u;Y>vJxs}f+W3vf{DXFXNO@TFhq9>nIuGVm@opl}Ob1LbF;+^M91}1|UtpMGI1174g&!CW z)9^Y*7e;XWCr}chXXcw-3><|~`t?6tloJh(Fm*Kb5z2xfYwj4$FhbIY zeS|*YT*VL$&`*R+W{f#jK^&)HU!lVQCrda$Ff|o287SgN0sudbY}bn}pa6{J4*)>`#)=MrK!RjhXJ`<}a#twJ0U8L#IY0w3V=~c% zKcW-_aZrUpU=-#U!APz`3?*3O13)lAaDrnd>PH%5A7C&Tz*)ltFa_fZlLQ-47_7z+ zj)MdOuuuSinTPBQ!Z1of+=m3axfmlP8yo-_205955gg&@LpXblk;T5rQa@}H0)W_c zhjH{LP#0zkM*amOFbw@Mt-^N*(?)D(5P-ygnk!-cnPdShL;_#}gjvH2ATSAWXb23j zONTHG$1Vv1{>!$*A&6o(4T2HSPaX;#WOgMxGYAP2Y^MzNXHX_SR;odixqdjZ zAc22(n)-HWqYU=5x*tR#m}?k9*b9q!hZ5fve%HsD9OfOf^I1+$nV3a7AV}226G8Zh znQ+uiF=QENW^Qg~#%Hcc05?Zra|l6<)C~Ub6Av{bBdKj6Ucn*Z!G7zdKokaWOiD}3 I%+6fuzd7 '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 DEBUG JSDEBUG html - js_encode_function cgi_header_extra); - - CGI::Ajax->mk_accessors( @METHODS ); - - $VERSION = .697; -} - -########################################### 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; - } - -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. - -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->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) - - #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 ( 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.*/ ) { - 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->cgi()->header(); - $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 $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) + ' 
    '; - } - document.getElementById('pjxdebugrequest').innerHTML = tmp + "
    "; -} - -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 wil be desplayed 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 = ""; - if ( $self->cgi()->can('header') ) { - $rv = $self->cgi()->header( $self->cgi_header_extra() ); - } else { - # 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->cgi()->param("fname"); - - # 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" ) { - eval { ($result, @other) = $code->( $self->cgi()->param("args") ) }; - - if ($@) { - # see if the eval caused and error and report it - # Should we be more severe and die? - if ( $self->DEBUG() ) { - 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->cgi()->remote_addr(); - print STDERR "\trequested URL: ", $self->cgi()->url(); - print STDERR "\tfname request: ", $self->cgi()->param('fname'); - print STDERR " -- returning Bad Request status 400\n"; - if ( $self->cgi()->can('header') ) { - return($self->cgi()->header( -status=>'400' )); - } else { - # 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()"; - } - - #create the javascript text - $rv .= <JSDEBUG() ) { - $rv = $self->compress_js($rv); - } - return $rv; -} - -=item register() - - Purpose: adds a function name and a code ref to the global coderef - hash, after the original object was created - Arguments: function name, code reference - Returns: none - Called By: originating web script - -=cut - -sub register { - my ( $self, $fn, $coderef ) = @_; - # coderef_list() is a Class::Accessor function - # url_list() is a Class::Accessor function - if ( ref( $coderef ) eq "CODE" ) { - $self->coderef_list()->{$fn} = $coderef; - } elsif ( ref($coderef) ) { - die "Unsupported code/url type - error\n"; - } else { - $self->url_list()->{$fn} = $coderef; - } -} - -=item JSDEBUG() - - Purpose: Show the AJAX URL that is being generated, and stop - compression of the generated javascript, both of which can aid - during debugging. 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. - - Arguments: JSDEBUG(0); # turn javascript debugging off - JSDEBUG(1); # turn javascript debugging on, some javascript compression - JSDEBUG(2); # turn javascript debugging on, no javascript compresstion - Returns: prints a link to the url that is being generated automatically by - the Ajax object. this is VERY useful for seeing what - CGI::Ajax is doing. Following the link, will show a page - with the output that the page is generating. - - Called By: $pjx->JSDEBUG(1) # where $pjx is a CGI::Ajax object; - -=item DEBUG() - - Purpose: Show debugging information in web server logs - Arguments: DEBUG(0); # turn debugging off (default) - DEBUG(1); # turn debugging on - Returns: prints debugging information to the web server logs using - STDERR - Called By: $pjx->DEBUG(1) # where $pjx is a CGI::Ajax object; - -=back - -=head1 BUGS - -Follow any bugs at our homepage.... - - http://www.perljax.us - -=head1 SUPPORT - -Check out the news/discussion/bugs lists at our homepage: - - http://www.perljax.us - -=head1 AUTHORS - - Brian C. Thomas Brent Pedersen - CPAN ID: BCT - bct.x42@gmail.com bpederse@gmail.com - -=head1 A NOTE ABOUT THE MODULE NAME - -This module was initiated using the name "Perljax", but then -registered with CPAN under the WWW group "CGI::", and so became -"CGI::Perljax". Upon further deliberation, we decided to change it's -name to L. - -=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__ -- 2.20.1