JavaScript-RPC-0.1/ 40777 0 0 0 10321101506 12201 5ustar usergroupJavaScript-RPC-0.1/Build.PL100666 0 0 637 10321075573 13576 0ustar usergroupuse strict; use Module::Build; my $build = Module::Build->new( module_name => 'JavaScript::RPC', dist_version_from => 'lib/JavaScript/RPC/Server/CGI.pm', dist_author => 'Brian Cassidy ', license => 'perl', create_readme => 1, create_makefile_pl => 'traditional', build_requres => { 'Test::More' => 0 } ); $build->create_build_script;JavaScript-RPC-0.1/Changes100666 0 0 2340 10321101430 13564 0ustar usergroupRevision history for Perl extension JavaScript::RPC::Server::CGI. 0.1 Wed Oct 05 2005 - Fixed multi-line parameter handling (thanks to Tyler MacDonald) - Switched to Module::Build 0.06 Wed Mar 02 11:25:16 2005 - added pod_coverage test 0.05 Wed Aug 11 10:21:30 2004 - Subs no longer need to return error() or result() just die() or return() - query() now sets env() at the same time - Added new tests - Updated demo script 0.04 Fri Jan 30 21:24:36 2004 - Added missing _js_escape() sub - Documenation fixed - env() now returns a hash on set - Added get_new_query() - used by query() 0.03 Sat Jan 24 22:54:22 2004 - Fixed example programs - Added string escaping to error() - Fixed env() 0.02 Sat Jan 17 12:36:32 2004 *** IMPORTANT - This module must now be subclassed in order to add custom methods (the method() sub has been removed) *** - Added error_message method - Renamed info() to env() - Added ABSTRACT to Makefile.PL - Updated demo to work with new module format - Updated README - Query object problems have magically gone away 0.01 Thu Jan 15 10:56:07 2004 - original version; created by h2xs 1.23 with options -X -n JavaScript::RPC::Server::CGI JavaScript-RPC-0.1/demo/ 40777 0 0 0 10321101506 13125 5ustar usergroupJavaScript-RPC-0.1/demo/jsrpc.pl100666 0 0 1162 10106412214 14702 0ustar usergroup#!/usr/bin/perl -w package MyJSRPC; use Carp; use base qw( JavaScript::RPC::Server::CGI ); sub add { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] + $args[ 1 ]; } sub subtract { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] - $args[ 1 ]; } package main; use strict; my $server = MyJSRPC->new; $server->process;JavaScript-RPC-0.1/demo/jsrsClient.js100666 0 0 25275 10001535543 15742 0ustar usergroup// // jsrsClient.js - javascript remote scripting client include // // Author: Brent Ashley [jsrs@megahuge.com] // // make asynchronous remote calls to server without client page refresh // // see license.txt for copyright and license information /* see history.txt for full history 2.0 26 Jul 2001 - added POST capability for IE/MOZ 2.2 10 Aug 2003 - added Opera support 2.3(beta) 10 Oct 2003 - added Konqueror support - **needs more testing** */ // callback pool needs global scope var jsrsContextPoolSize = 0; var jsrsContextMaxPool = 10; var jsrsContextPool = new Array(); var jsrsBrowser = jsrsBrowserSniff(); var jsrsPOST = true; var containerName; // constructor for context object function jsrsContextObj( contextID ){ // properties this.id = contextID; this.busy = true; this.callback = null; this.container = contextCreateContainer( contextID ); // methods this.GET = contextGET; this.POST = contextPOST; this.getPayload = contextGetPayload; this.setVisibility = contextSetVisibility; } // method functions are not privately scoped // because Netscape's debugger chokes on private functions function contextCreateContainer( containerName ){ // creates hidden container to receive server data var container; switch( jsrsBrowser ) { case 'NS': container = new Layer(100); container.name = containerName; container.visibility = 'hidden'; container.clip.width = 100; container.clip.height = 100; break; case 'IE': document.body.insertAdjacentHTML( "afterBegin", '' ); var span = document.all( "SPAN" + containerName ); var html = ''; span.innerHTML = html; span.style.display = 'none'; container = window.frames[ containerName ]; break; case 'MOZ': var span = document.createElement('SPAN'); span.id = "SPAN" + containerName; document.body.appendChild( span ); var iframe = document.createElement('IFRAME'); iframe.name = containerName; iframe.id = containerName; span.appendChild( iframe ); container = iframe; break; case 'OPR': var span = document.createElement('SPAN'); span.id = "SPAN" + containerName; document.body.appendChild( span ); var iframe = document.createElement('IFRAME'); iframe.name = containerName; iframe.id = containerName; span.appendChild( iframe ); container = iframe; break; case 'KONQ': var span = document.createElement('SPAN'); span.id = "SPAN" + containerName; document.body.appendChild( span ); var iframe = document.createElement('IFRAME'); iframe.name = containerName; iframe.id = containerName; span.appendChild( iframe ); container = iframe; // Needs to be hidden for Konqueror, otherwise it'll appear on the page span.style.display = none; iframe.style.display = none; iframe.style.visibility = hidden; iframe.height = 0; iframe.width = 0; break; } return container; } function contextPOST( rsPage, func, parms ){ var d = new Date(); var unique = d.getTime() + '' + Math.floor(1000 * Math.random()); var doc = (jsrsBrowser == "IE" ) ? this.container.document : this.container.contentDocument; doc.open(); doc.write(''); doc.write('
'); doc.write(''); // func and parms are optional if (func != null){ doc.write(''); if (parms != null){ if (typeof(parms) == "string"){ // single parameter doc.write( ''); } else { // assume parms is array of strings for( var i=0; i < parms.length; i++ ){ doc.write( ''); } } // parm type } // parms } // func doc.write('
'); doc.close(); doc.forms['jsrsForm'].submit(); } function contextGET( rsPage, func, parms ){ // build URL to call var URL = rsPage; // always send context URL += "?C=" + this.id; // func and parms are optional if (func != null){ URL += "&F=" + escape(func); if (parms != null){ if (typeof(parms) == "string"){ // single parameter URL += "&P0=[" + escape(parms+'') + "]"; } else { // assume parms is array of strings for( var i=0; i < parms.length; i++ ){ URL += "&P" + i + "=[" + escape(parms[i]+'') + "]"; } } // parm type } // parms } // func // unique string to defeat cache var d = new Date(); URL += "&U=" + d.getTime(); // make the call switch( jsrsBrowser ) { case 'NS': this.container.src = URL; break; case 'IE': this.container.document.location.replace(URL); break; case 'MOZ': this.container.src = ''; this.container.src = URL; break; case 'OPR': this.container.src = ''; this.container.src = URL; break; case 'KONQ': this.container.src = ''; this.container.src = URL; break; } } function contextGetPayload(){ switch( jsrsBrowser ) { case 'NS': return this.container.document.forms['jsrs_Form'].elements['jsrs_Payload'].value; case 'IE': return this.container.document.forms['jsrs_Form']['jsrs_Payload'].value; case 'MOZ': return window.frames[this.container.name].document.forms['jsrs_Form']['jsrs_Payload'].value; case 'OPR': var textElement = window.frames[this.container.name].document.getElementById("jsrs_Payload"); case 'KONQ': var textElement = window.frames[this.container.name].document.getElementById("jsrs_Payload"); return textElement.value; } } function contextSetVisibility( vis ){ switch( jsrsBrowser ) { case 'NS': this.container.visibility = (vis)? 'show' : 'hidden'; break; case 'IE': document.all("SPAN" + this.id ).style.display = (vis)? '' : 'none'; break; case 'MOZ': document.getElementById("SPAN" + this.id).style.visibility = (vis)? '' : 'hidden'; case 'OPR': document.getElementById("SPAN" + this.id).style.visibility = (vis)? '' : 'hidden'; this.container.width = (vis)? 250 : 0; this.container.height = (vis)? 100 : 0; break; } } // end of context constructor function jsrsGetContextID(){ var contextObj; for (var i = 1; i <= jsrsContextPoolSize; i++){ contextObj = jsrsContextPool[ 'jsrs' + i ]; if ( !contextObj.busy ){ contextObj.busy = true; return contextObj.id; } } // if we got here, there are no existing free contexts if ( jsrsContextPoolSize <= jsrsContextMaxPool ){ // create new context var contextID = "jsrs" + (jsrsContextPoolSize + 1); jsrsContextPool[ contextID ] = new jsrsContextObj( contextID ); jsrsContextPoolSize++; return contextID; } else { alert( "jsrs Error: context pool full" ); return null; } } function jsrsExecute( rspage, callback, func, parms, visibility ){ // call a server routine from client code // // rspage - href to asp file // callback - function to call on return // or null if no return needed // (passes returned string to callback) // func - sub or function name to call // parm - string parameter to function // or array of string parameters if more than one // visibility - optional boolean to make container visible for debugging // get context var contextObj = jsrsContextPool[ jsrsGetContextID() ]; contextObj.callback = callback; var vis = (visibility == null)? false : visibility; contextObj.setVisibility( vis ); if ( jsrsPOST && ((jsrsBrowser == 'IE') || (jsrsBrowser == 'MOZ'))){ contextObj.POST( rspage, func, parms ); } else { contextObj.GET( rspage, func, parms ); } return contextObj.id; } function jsrsLoaded( contextID ){ // get context object and invoke callback var contextObj = jsrsContextPool[ contextID ]; if( contextObj.callback != null){ contextObj.callback( jsrsUnescape( contextObj.getPayload() ), contextID ); } // clean up and return context to pool contextObj.callback = null; contextObj.busy = false; } function jsrsError( contextID, str ){ alert( unescape(str) ); jsrsContextPool[ contextID ].busy = false } function jsrsEscapeQQ( thing ){ return thing.replace(/'"'/g, '\\"'); } function jsrsUnescape( str ){ // payload has slashes escaped with whacks return str.replace( /\\\//g, "/" ); } function jsrsBrowserSniff(){ if (document.layers) return "NS"; if (document.all) { // But is it really IE? // convert all characters to lowercase to simplify testing var agt=navigator.userAgent.toLowerCase(); var is_opera = (agt.indexOf("opera") != -1); var is_konq = (agt.indexOf("konqueror") != -1); if(is_opera) { return "OPR"; } else { if(is_konq) { return "KONQ"; } else { // Really is IE return "IE"; } } } if (document.getElementById) return "MOZ"; return "OTHER"; } ///////////////////////////////////////////////// // // user functions function jsrsArrayFromString( s, delim ){ // rebuild an array returned from server as string // optional delimiter defaults to ~ var d = (delim == null)? '~' : delim; return s.split(d); } function jsrsDebugInfo(){ // use for debugging by attaching to f1 (works with IE) // with onHelp = "return jsrsDebugInfo();" in the body tag var doc = window.open().document; doc.open; doc.write( 'Pool Size: ' + jsrsContextPoolSize + '
' ); for( var i in jsrsContextPool ){ var contextObj = jsrsContextPool[i]; doc.write( '
' + contextObj.id + ' : ' + (contextObj.busy ? 'busy' : 'available') + '
'); doc.write( contextObj.container.document.location.pathname + '
'); doc.write( contextObj.container.document.location.search + '
'); doc.write( '
' + contextObj.container.document.body.innerHTML + '
' ); } doc.write(''); doc.close(); return false; } JavaScript-RPC-0.1/demo/test.html100666 0 0 2533 10004633772 15107 0ustar usergroup JavaScript Remote Procedure Call Demo

Javascript Remote Procedure Call Demo

Add or subtract two numbers:

use POST

JavaScript-RPC-0.1/lib/ 40777 0 0 0 10321101506 12747 5ustar usergroupJavaScript-RPC-0.1/lib/JavaScript/ 40777 0 0 0 10321101506 15015 5ustar usergroupJavaScript-RPC-0.1/lib/JavaScript/RPC/ 40777 0 0 0 10321101506 15441 5ustar usergroupJavaScript-RPC-0.1/lib/JavaScript/RPC/Server/ 40777 0 0 0 10321101506 16707 5ustar usergroupJavaScript-RPC-0.1/lib/JavaScript/RPC/Server/CGI.pm100666 0 0 15010 10321076524 17774 0ustar usergrouppackage JavaScript::RPC::Server::CGI; use strict; use Carp; our $VERSION = '0.1'; =head1 NAME JavaScript::RPC::Server::CGI - Remote procedure calls from JavaScript =head1 SYNOPSIS package MyJSRPC; use Carp; use base qw( JavaScript::RPC::Server::CGI ); sub add { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] + $args[ 1 ]; } sub subtract { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] - $args[ 1 ]; } package main; use strict; my $server = MyJSRPC->new; $server->process; =head1 DESCRIPTION JavaScript::RPC::Server::CGI is a CGI-based server library for use with Brent Ashley's JavaScript Remote Scripting (JSRS) client library. It works asynchronously and uses DHTML to deal with the payload. In order to add your custom meothds, this module should be subclassed. The most current version (as of the release of this module) of the client library as well as a demo application have been included in this distribution. =head1 INSTALLATION To install this module via Module::Build: perl Build.PL ./Build # or `perl Build` ./Build test # or `perl Build test` ./Build install # or `perl Build install` To install this module via ExtUtils::MakeMaker: perl Makefile.PL make make test make install =head1 METHODS =head2 new() Creates a new instance of the module. No further options are available at this time. =cut sub new { my $class = shift; my $self = { env => {} }; bless $self, $class; return $self; } =head2 query() Gets / sets the query object. This has the side effect of extracting the env() data. =cut sub query { my $self = shift; my $query = shift; unless( $query or $self->{ query } ) { $query = $self->get_new_query; } if( $query ) { my $method = $query->param( 'F' ) || undef; my $uid = $query->param( 'U' ) || undef; my $context = $query->param( 'C' ) || undef; my( $param, @params ); my $i = 0; # Extract parameters while( defined( $param = $query->param( "P$i" ) ) ) { $param =~ s/^\[(.*)\]$/$1/s; push @params, $param; $i++; } $self->env( method => $method, uid => $uid, context => $context, params => \@params ); $self->{ query } = $query; } return $self->{ query }; } =head2 get_new_query() This method generates a new query object. It is used internally by the query() method. This method should only be used if you want to supply a query object other than the standard CGI.pm object. However, it must be a CGI.pm compatible object. Here's an example using CGI::Simple. sub get_new_query { require CGI::Simple; my $q = CGI::Simple->new(); return $q; } =cut sub get_new_query { require CGI; my $q = CGI->new(); return $q; } =head2 env() Gets / sets a hash of information related to the currently query. The resulting structure contains four items: =over 4 =item * method - the method called =item * params - an array of parameters for the method =item * uid - the unique id for this query =item * context - the context id =back =cut sub env { my $self = shift; if( @_ ) { if( @_ % 2 == 0 ) { my %env = @_; for( keys %env ) { $self->{ env }->{ $_ } = $env{ $_ }; } } else { return $self->{ env }->{ $_[ 0 ] }; } } else { $self->query; } return %{ $self->{ env } }; } =head2 error_message() Get / sets the error message sent to the client if an error occurred. =cut sub error_message { my $self = shift; my $message = shift; $self->{ error_message } = $message if $message; return $self->{ error_message }; } =head2 process() Processes the current query and either returns the result from the appropriate method, or an error to the client and returns either true or false, respectively, to the caller. An error will occur if the method name is blank, or the method has not been defined. This function takes an optional CGI.pm compatible object as an input. Your subclass' method will be evaled and will either return an error to the caller if it died, or return a valid result payload on success. =cut sub process { my $self = shift; my $query = $self->query; my $method = $self->env( 'method' ); my @params = @{ $self->env( 'params' ) }; print $query->header; return $self->error( 'No function specified' ) unless $method; return $self->error( 'Specified function not implemented' ) unless $self->can( $method ); eval { return $self->result( $self->$method( @params ) ); }; return $self->error( $@ ) if $@; } =head2 error() Returns a valid error payload to the client and false to the caller. It will automatically call error_message() for you. =cut sub error { my $self = shift; my $message = shift; $message =~ s/(.+) at (.+?)\n*$/$1/; my $msg_esc = _js_escape( $message ); my %env = $self->env; $self->error_message( $message ); carp( $message ); print <<"EO_ERROR"; $message EO_ERROR return 0; } =head2 result() Returns a valid result payload to the client and true to the caller. =cut sub result { my $self = shift; my $message = shift; my %env = $self->env; print <<"EO_RESULT"; jsrsPayload:
EO_RESULT return 1; } =head1 SEE ALSO =over 4 =item * http://www.ashleyit.com/rs =back =head1 AUTHOR =over 4 =item * Brian Cassidy Ebrian@alternation.netE =back =head1 COPYRIGHT AND LICENSE Copyright 2005 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut sub _js_escape { my $string = shift; $string =~ s/'/\\'/g; $string =~ s/\n/\\r/gs; return $string; } 1;JavaScript-RPC-0.1/Makefile.PL100666 0 0 515 10321101506 14231 0ustar usergroup# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'JavaScript::RPC', 'VERSION_FROM' => 'lib/JavaScript/RPC/Server/CGI.pm', 'PREREQ_PM' => {}, 'INSTALLDIRS' => 'site', 'PL_FILES' => {} ) ; JavaScript-RPC-0.1/MANIFEST100666 0 0 405 10321101506 13406 0ustar usergroupBuild.PL Changes demo/jsrpc.pl demo/jsrsClient.js demo/test.html lib/JavaScript/RPC/Server/CGI.pm META.yml MANIFEST t/01-use.t t/02-query.t t/03-env.t t/04-result.t t/05-error.t t/06-process.t t/98-pod_coverage.t t/99-pod.t Makefile.PL README JavaScript-RPC-0.1/META.yml100666 0 0 470 10321101505 13527 0ustar usergroup--- #YAML:1.0 name: JavaScript-RPC version: 0.1 author: - Brian Cassidy abstract: Remote procedure calls from JavaScript license: perl provides: JavaScript::RPC::Server::CGI: file: lib/JavaScript/RPC/Server/CGI.pm version: 0.1 generated_by: Module::Build version 0.2611 JavaScript-RPC-0.1/README100666 0 0 10374 10321101506 13203 0ustar usergroupNAME JavaScript::RPC::Server::CGI - Remote procedure calls from JavaScript SYNOPSIS package MyJSRPC; use Carp; use base qw( JavaScript::RPC::Server::CGI ); sub add { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] + $args[ 1 ]; } sub subtract { my $self = shift; my @args = @_; unless( @args == 2 and $args[ 0 ] =~ /^\d+$/ and $args[ 1 ] =~ /^\d+$/ ) { croak( 'inputs must be digits only' ); } return $args[ 0 ] - $args[ 1 ]; } package main; use strict; my $server = MyJSRPC->new; $server->process; DESCRIPTION JavaScript::RPC::Server::CGI is a CGI-based server library for use with Brent Ashley's JavaScript Remote Scripting (JSRS) client library. It works asynchronously and uses DHTML to deal with the payload. In order to add your custom meothds, this module should be subclassed. The most current version (as of the release of this module) of the client library as well as a demo application have been included in this distribution. INSTALLATION To install this module via Module::Build: perl Build.PL ./Build # or `perl Build` ./Build test # or `perl Build test` ./Build install # or `perl Build install` To install this module via ExtUtils::MakeMaker: perl Makefile.PL make make test make install METHODS new() Creates a new instance of the module. No further options are available at this time. query() Gets / sets the query object. This has the side effect of extracting the env() data. get_new_query() This method generates a new query object. It is used internally by the query() method. This method should only be used if you want to supply a query object other than the standard CGI.pm object. However, it must be a CGI.pm compatible object. Here's an example using CGI::Simple. sub get_new_query { require CGI::Simple; my $q = CGI::Simple->new(); return $q; } env() Gets / sets a hash of information related to the currently query. The resulting structure contains four items: * method - the method called * params - an array of parameters for the method * uid - the unique id for this query * context - the context id error_message() Get / sets the error message sent to the client if an error occurred. process() Processes the current query and either returns the result from the appropriate method, or an error to the client and returns either true or false, respectively, to the caller. An error will occur if the method name is blank, or the method has not been defined. This function takes an optional CGI.pm compatible object as an input. Your subclass' method will be evaled and will either return an error to the caller if it died, or return a valid result payload on success. error() Returns a valid error payload to the client and false to the caller. It will automatically call error_message() for you. result() Returns a valid result payload to the client and true to the caller. SEE ALSO * http://www.ashleyit.com/rs AUTHOR * Brian Cassidy COPYRIGHT AND LICENSE Copyright 2005 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. JavaScript-RPC-0.1/t/ 40777 0 0 0 10321101506 12444 5ustar usergroupJavaScript-RPC-0.1/t/01-use.t100666 0 0 124 10106411000 13707 0ustar usergroupuse Test::More tests => 1; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) };JavaScript-RPC-0.1/t/02-query.t100666 0 0 1512 10106435701 14321 0ustar usergrouppackage MyJSRPC; use base qw( JavaScript::RPC::Server::CGI ); sub get_new_query { require CGI::Simple; my $q = CGI::Simple->new(); return $q; } package main; use Test::More tests => 7; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) }; use strict; use warnings; my $server = JavaScript::RPC::Server::CGI->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); isa_ok( $server->query, 'CGI' ); $server = JavaScript::RPC::Server::CGI->new; my $query = CGI->new( { test => 'data' } ); $server->query( $query ); isa_ok( $server->query, 'CGI' ); is( $server->query->param( 'test' ), 'data' ); SKIP: { eval "use CGI::Simple"; skip 'CGI::Simple required', 2 if $@; $server = MyJSRPC->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); isa_ok( $server->query, 'CGI::Simple' ); }JavaScript-RPC-0.1/t/03-env.t100666 0 0 1175 10106435701 13752 0ustar usergroupuse Test::More tests => 4; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) }; use strict; use warnings; my $server = JavaScript::RPC::Server::CGI->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); is_deeply( { $server->env }, { method => undef, uid => undef, context => undef, params => [] } ); my $query = CGI->new( { C => 'jsrs6', F => 'add', P0 => '[1]', P1 => '[2]', U => '1092142818812' } ); $server->query( $query ); is_deeply( { $server->env }, { method => 'add', uid => '1092142818812', context => 'jsrs6', params => [ 1, 2 ] } ); JavaScript-RPC-0.1/t/04-result.t100666 0 0 1635 10106435701 14502 0ustar usergroupuse Test::More tests => 3; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) }; use strict; use warnings; use CGI; my $server = JavaScript::RPC::Server::CGI->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); my $query = CGI->new( { C => 'jsrs6', F => 'add', P0 => '[0]', P1 => '[1]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 1 if $@; my $capture = IO::Capture::Stdout->new; $capture->start; $server->result( 1 ); $capture->stop; my @lines = $capture->read; my $text = < jsrsPayload:
EORESULT is( join( '', @lines ), $text ); }JavaScript-RPC-0.1/t/05-error.t100666 0 0 2445 10106450352 14315 0ustar usergroupuse Test::More tests => 7; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) }; use strict; use warnings; use CGI; my $server = JavaScript::RPC::Server::CGI->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); is( $server->error_message, undef ); $server->error_message( 'test' ); is( $server->error_message, 'test' ); my $query = CGI->new( { C => 'jsrs6', F => 'add', P0 => '[0]', P1 => '[1]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 3 if $@; eval "use IO::Capture::Stderr"; skip 'IO::Capture::Stderr required', 3 if $@; my $capturestdout = IO::Capture::Stdout->new; my $capturestderr = IO::Capture::Stderr->new; $capturestdout->start; $capturestderr->start; $server->error( 1 ); $capturestdout->stop; $capturestderr->stop; my @lineserr = $capturestderr->read; my $texterr = '1 at ' . __FILE__ . " line 42\n"; my @linesout = $capturestdout->read; my $textout = < 1 EORESULT is( join( '', @lineserr ), $texterr ); is( $server->error_message, '1' ); is( join( '', @linesout ), $textout ); }JavaScript-RPC-0.1/t/06-process.t100666 0 0 11617 10321074323 14663 0ustar usergrouppackage MyJSRPC; use base qw( JavaScript::RPC::Server::CGI ); sub add { my $self = shift; if( @_ == 2 ) { return $_[ 0 ] + $_[ 1 ]; } else { die '2 numbers are needed'; } } sub echo { return $_[ 1 ]; } package main; use Test::More tests => 13; BEGIN { use_ok( 'JavaScript::RPC::Server::CGI' ) }; use strict; use warnings; use CGI; my $server = MyJSRPC->new; isa_ok( $server, 'JavaScript::RPC::Server::CGI' ); my $query = CGI->new( { C => 'jsrs6', F => 'add', P0 => '[2]', P1 => '[1]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 1 if $@; my $capture = IO::Capture::Stdout->new; $capture->start; $server->process; $capture->stop; my @lines = $capture->read; my $text = < jsrsPayload:
EOT1 is( join( '', $lines[ 1 ] ), $text ); } $query = CGI->new( { C => 'jsrs6', F => '', P0 => '[2]', P1 => '[1]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 3 if $@; eval "use IO::Capture::Stderr"; skip 'IO::Capture::Stderr required', 3 if $@; my $capturestdout = IO::Capture::Stdout->new; my $capturestderr = IO::Capture::Stderr->new; $capturestdout->start; $capturestderr->start; $server->process; $capturestdout->stop; $capturestderr->stop; my @lineserr = $capturestderr->read; my $texterr = 'No function specified at ' . __FILE__ . " line 89\n"; my @linesout = $capturestdout->read; my $textout = < No function specified EOT2 is( join( '', @lineserr ), $texterr ); is( $server->error_message, 'No function specified' ); is( join( '', $linesout[ 1 ] ), $textout ); } $query = CGI->new( { C => 'jsrs6', F => 'add2', P0 => '[2]', P1 => '[1]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 3 if $@; eval "use IO::Capture::Stderr"; skip 'IO::Capture::Stderr required', 3 if $@; my $capturestdout = IO::Capture::Stdout->new; my $capturestderr = IO::Capture::Stderr->new; $capturestdout->start; $capturestderr->start; $server->process; $capturestdout->stop; $capturestderr->stop; my @lineserr = $capturestderr->read; my $texterr = 'Specified function not implemented at ' . __FILE__ . " line 127\n"; my @linesout = $capturestdout->read; my $textout = < Specified function not implemented EOT2 is( join( '', @lineserr ), $texterr ); is( $server->error_message, 'Specified function not implemented' ); is( join( '', $linesout[ 1 ] ), $textout ); } $query = CGI->new( { C => 'jsrs6', F => 'add', P0 => '[2]', U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 3 if $@; eval "use IO::Capture::Stderr"; skip 'IO::Capture::Stderr required', 3 if $@; my $capturestdout = IO::Capture::Stdout->new; my $capturestderr = IO::Capture::Stderr->new; $capturestdout->start; $capturestderr->start; $server->process; $capturestdout->stop; $capturestderr->stop; my @lineserr = $capturestderr->read; my $texterr = '2 numbers are needed at ' . __FILE__ . " line 164\n"; my @linesout = $capturestdout->read; my $textout = < 2 numbers are needed EOT2 is( join( '', @lineserr ), $texterr ); is( $server->error_message, '2 numbers are needed' ); is( join( '', $linesout[ 1 ] ), $textout ); } $query = CGI->new( { C => 'jsrs6', F => 'echo', P0 => "[foo\nbar]", U => '1092142818812' } ); $server->query( $query ); SKIP: { eval "use IO::Capture::Stdout"; skip 'IO::Capture::Stdout required', 1 if $@; my $capture = IO::Capture::Stdout->new; $capture->start; $server->process; $capture->stop; my @lines = $capture->read; my $text = < jsrsPayload:
EOT1 is( join( '', $lines[ 1 ] ), $text, 'multi-line param' ); } JavaScript-RPC-0.1/t/98-pod_coverage.t100666 0 0 243 10211364724 15613 0ustar usergroupuse Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok();JavaScript-RPC-0.1/t/99-pod.t100666 0 0 205 10106411150 13724 0ustar usergroupuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();