#! /usr/bin/perl -w # Perl version cloned from the original PHP by http://www.modernmethod.com/sajax/ # I've left commented-out examples in the code for running with static methods. # For moving to ModPerl it's important to no be redefining subs all the time, # so this code adds the rs_register(funcname,coderef) call, which takes a coderef # rather than the name of a sub to be called. use Sajax; use CGI; my $q = new CGI; my $rv = ""; $rv .= "content-type: text/html\n\n"; =pod #for static method calls sub Sajax::multiply { my($x, $y)=@_; return $x * $y; } sub Sajax::divide { my($x, $y)=@_; return $x / $y; } =cut #equivalent modperl methods my $msub = sub { my($x, $y)=@_; return $x * $y; }; my $dsub = sub { my($x, $y)=@_; return $x / $y; }; Sajax::rs_init(); #register static methods (called by name) #Sajax::rs_export("multiply","divide"); #modperl methods (called as anonymous coderefs) Sajax::rs_register("multiply",$msub); Sajax::rs_register("divide",$dsub); my $handled_value = Sajax::rs_handle_client_request($q); if(defined $handled_value) { $rv .= $handled_value; } else { $rv .= "\n
\n