| 1 |
NAME |
| 2 |
JavaScript::RPC::Server::CGI - Remote procedure calls from JavaScript |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
package MyJSRPC; |
| 6 |
|
| 7 |
use Carp; |
| 8 |
use base qw( JavaScript::RPC::Server::CGI ); |
| 9 |
|
| 10 |
sub add { |
| 11 |
my $self = shift; |
| 12 |
my @args = @_; |
| 13 |
unless( |
| 14 |
@args == 2 and |
| 15 |
$args[ 0 ] =~ /^\d+$/ and |
| 16 |
$args[ 1 ] =~ /^\d+$/ |
| 17 |
) { |
| 18 |
croak( 'inputs must be digits only' ); |
| 19 |
} |
| 20 |
return $args[ 0 ] + $args[ 1 ]; |
| 21 |
} |
| 22 |
|
| 23 |
sub subtract { |
| 24 |
my $self = shift; |
| 25 |
my @args = @_; |
| 26 |
unless( |
| 27 |
@args == 2 and |
| 28 |
$args[ 0 ] =~ /^\d+$/ and |
| 29 |
$args[ 1 ] =~ /^\d+$/ |
| 30 |
) { |
| 31 |
croak( 'inputs must be digits only' ); |
| 32 |
} |
| 33 |
return $args[ 0 ] - $args[ 1 ]; |
| 34 |
} |
| 35 |
|
| 36 |
package main; |
| 37 |
|
| 38 |
use strict; |
| 39 |
|
| 40 |
my $server = MyJSRPC->new; |
| 41 |
$server->process; |
| 42 |
|
| 43 |
DESCRIPTION |
| 44 |
JavaScript::RPC::Server::CGI is a CGI-based server library for use with |
| 45 |
Brent Ashley's JavaScript Remote Scripting (JSRS) client library. It |
| 46 |
works asynchronously and uses DHTML to deal with the payload. |
| 47 |
|
| 48 |
In order to add your custom meothds, this module should be subclassed. |
| 49 |
|
| 50 |
The most current version (as of the release of this module) of the |
| 51 |
client library as well as a demo application have been included in this |
| 52 |
distribution. |
| 53 |
|
| 54 |
INSTALLATION |
| 55 |
To install this module via Module::Build: |
| 56 |
|
| 57 |
perl Build.PL |
| 58 |
./Build # or `perl Build` |
| 59 |
./Build test # or `perl Build test` |
| 60 |
./Build install # or `perl Build install` |
| 61 |
|
| 62 |
To install this module via ExtUtils::MakeMaker: |
| 63 |
|
| 64 |
perl Makefile.PL |
| 65 |
make |
| 66 |
make test |
| 67 |
make install |
| 68 |
|
| 69 |
METHODS |
| 70 |
new() |
| 71 |
Creates a new instance of the module. No further options are available |
| 72 |
at this time. |
| 73 |
|
| 74 |
query() |
| 75 |
Gets / sets the query object. This has the side effect of extracting the |
| 76 |
env() data. |
| 77 |
|
| 78 |
get_new_query() |
| 79 |
This method generates a new query object. It is used internally by the |
| 80 |
query() method. This method should only be used if you want to supply a |
| 81 |
query object other than the standard CGI.pm object. However, it must be |
| 82 |
a CGI.pm compatible object. Here's an example using CGI::Simple. |
| 83 |
|
| 84 |
sub get_new_query { |
| 85 |
require CGI::Simple; |
| 86 |
my $q = CGI::Simple->new(); |
| 87 |
|
| 88 |
return $q; |
| 89 |
} |
| 90 |
|
| 91 |
env() |
| 92 |
Gets / sets a hash of information related to the currently query. The |
| 93 |
resulting structure contains four items: |
| 94 |
|
| 95 |
* method - the method called |
| 96 |
* params - an array of parameters for the method |
| 97 |
* uid - the unique id for this query |
| 98 |
* context - the context id |
| 99 |
|
| 100 |
error_message() |
| 101 |
Get / sets the error message sent to the client if an error occurred. |
| 102 |
|
| 103 |
process() |
| 104 |
Processes the current query and either returns the result from the |
| 105 |
appropriate method, or an error to the client and returns either true or |
| 106 |
false, respectively, to the caller. An error will occur if the method |
| 107 |
name is blank, or the method has not been defined. This function takes |
| 108 |
an optional CGI.pm compatible object as an input. |
| 109 |
|
| 110 |
Your subclass' method will be evaled and will either return an error to |
| 111 |
the caller if it died, or return a valid result payload on success. |
| 112 |
|
| 113 |
error() |
| 114 |
Returns a valid error payload to the client and false to the caller. It |
| 115 |
will automatically call error_message() for you. |
| 116 |
|
| 117 |
result() |
| 118 |
Returns a valid result payload to the client and true to the caller. |
| 119 |
|
| 120 |
SEE ALSO |
| 121 |
* http://www.ashleyit.com/rs |
| 122 |
|
| 123 |
AUTHOR |
| 124 |
* Brian Cassidy <[email protected]> |
| 125 |
|
| 126 |
COPYRIGHT AND LICENSE |
| 127 |
Copyright 2005 by Brian Cassidy |
| 128 |
|
| 129 |
This library is free software; you can redistribute it and/or modify it |
| 130 |
under the same terms as Perl itself. |
| 131 |
|