JavaSc...r::CGI(3pm)
π JavaScript::RPC::Server::CGI π
okay bestie, so this is a page from the User Contributed Perl Documentation (that's the 3pm manual, iykyk) and it's literally about making remote procedure calls from JavaScript. yes, JavaScript calling your Perl. iconic crossover event.
β¨ NAME β¨
JavaScript::RPC::Server::CGI β Remote procedure calls from JavaScript π¦
β¨ SYNOPSIS β¨
here's the whole vibe, copy-paste ready, no cap:
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;
like. look at her. subclassing, two methods, process. main character energy fr fr π
β¨ DESCRIPTION β¨
JavaScript::RPC::Server::CGI is a CGI-based server library made to pair with Brent Ashley's JavaScript Remote Scripting (JSRS) client library. it works asynchronously and uses DHTML to deal with the payload. yes queen, DHTML, we love a retro moment πΈ
so the way that this works: in order to add your own custom methods, you have to subclass this module. that's not optional, bestie, that's the whole point. no subclass = no custom methods = sad.
and get this β the most current version (as of when this module was released, so like, don't @ me) of the client library, plus a demo application, have both been included in this distribution. freebies. we love to see it π
β¨ INSTALLATION β¨
via Module::Build
perl Build.PL
./Build # or `perl Build`
./Build test # or `perl Build test`
./Build install # or `perl Build install`
via ExtUtils::MakeMaker
perl Makefile.PL
make
make test
make install
pick your fighter, both paths get you there π«Ά
β¨ METHODS β¨
π new()
creates a new instance of the module. and that's it. no further options are available at this time β literally none, don't go looking, there's nothing else there.
π query()
gets / sets the query object. β οΈ side effect alert: this one extracts the env() data. so it's not just a cute getter/setter, it's doing stuff behind the scenes. periodt.
π get_new_query()
this method generates a brand new query object. it's used internally by the query() method, so like, it's usually doing its own thing backstage.
you should only reach for this if you want to supply a query object that isn't the standard CGI.pm object. BUT β huge but β it must be a CGI.pm compatible object. them's the rules. here's an example using CGI::Simple:
sub get_new_query {
require CGI::Simple;
my $q = CGI::Simple->new();
return $q;
}
see? compatible. slay.
π env()
gets / sets a hash of information related to the currently query. the resulting structure contains four items:
method- the method calledparams- an array of parameters for the methoduid- the unique id for this querycontext- the context id
four lil guys, all important π
π error_message()
get / sets the error message sent to the client if an error occurred. simple as.
π process()
this is the big one. processes the current query and either returns the result from the appropriate method, or an error to the client β and it returns either true or false, respectively, to the caller. so: success = true, error = false. got it? π§
an error will occur if the method name is blank, or if 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 it'll either return an error to the caller if it died, or return a valid result payload on success. no cap, that's the whole flow π₯
π error()
returns a valid error payload to the client and false to the caller. it will automatically call error_message() for you. so convenient. we're obsessed.
π result()
returns a valid result payload to the client and true to the caller. the happy path. the good ending π
β¨ SEE ALSO β¨
β¨ AUTHOR β¨
- Brian Cassidy
<brian@alternation.net>
β¨ 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.
and that's the whole page, bestie!! π
this was perl v5.32.1, dated 2022-01-10, from the User Contributed Perl Documentation. go forth and subclass responsibly, mwah ππ
π¦ where this page comes from
- debian bookworm: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjavascript-rpc-perl 0.10-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms