package JSON::RPC;
use strict;
our $VERSION = '1.06';
1;
__END__
=head1 NAME
JSON::RPC - JSON RPC 2.0 Server Implementation
=head1 SYNOPSIS
# app.psgi
use strict;
use JSON::RPC::Disp
atch;
my $dispatch = JSON::RPC::Dispatch->new(
prefix => "MyApp::JSONRPC::Handler",
router => Router::Simple->new( ... )
);
sub {
my $env = shift;
$dispat
ch->handle_psgi($env);
};
=head1 DESCRIPTION
JSON::RPC is a set of modules that implement JSON RPC 2.0 protocol.
If you are using old JSON::RPC code (up to 0.96), DO NOT EXPECT
YOUR COD
###############
package JSON::RPC::Legacy::Server::CGI;
use strict;
use CGI;
use JSON::RPC::Legacy::Server; # for old Perl 5.005
use base qw(JSON::RPC::Legacy::Server);
$JSON::RPC::Legacy::Server::
o($cgi->path_info);
$self;
}
sub retrieve_json_from_post {
my $json = $_[0]->cgi->param('POSTDATA');
return $json;
}
sub retrieve_json_from_get {
my $self = shift;
my $cgi
$cgi->path_info;
$method =~ s{^.*/}{};
$self->{path_info} =~ s{/?[^/]+$}{};
$self->json->encode({
version => '1.1',
method => $method,
params => $params,
}
package JSON::RPC::Constants;
use strict;
use parent qw(Exporter);
our @EXPORT_OK = qw(
JSONRPC_DEBUG
RPC_PARSE_ERROR
RPC_INVALID_REQUEST
RPC_METHOD_NOT_FOUND
RPC_INVALID_PARAMS
RT_TAGS = (all => \@EXPORT_OK);
my %constants;
BEGIN {
%constants = (
JSONRPC_DEBUG => $ENV{PERL_JSONRPC_DEBUG} ? 1 : 0,
RPC_PARSE_ERROR => -32700,
RPC_INVALID_RE
AME
JSON::RPC::Constants - Constants
=head1 SYNOPSIS
use JSON::RPC::Constants qw(:all);
# or, import one by one
=head1 DEBUG
=over 4
=item B<JSONRPC_DEBUG>
Set to true if PERL_JSONRPC_
package JSON::RPC::Procedure;
use strict;
use Carp ();
use Class::Accessor::Lite
new => 1,
rw => [ qw(
id
method
params
has_id
jsonrpc
) ]
;
1;
__
END__
=head1 NAME
JSON::RPC::Procedure - A JSON::RPC Procedure
=head1 SYNOPSIS
use JSON::RPC::Procedure;
my $procedure = JSON::RPC::Procedure->new(
id => ...,
method => ..
s => ...
jsonrpc => ...
has_id => ... (a flag that signals that a procedure appears to be a notification when not set)
);
=head1 DESCRIPTION
A container for JSON RPC procedure in
package JSON::RPC::Legacy;
use strict;
1;
__END__
=pod
=head1 NAME
JSON::RPC - Perl implementation of JSON-RPC 1.1 protocol
=head1 DESCRIPTION
JSON-RPC is a stateless and light-weight remote p
r HTTP. It uses JSON
as the data format for of all facets of a remote procedure call,
including all application data carried in parameters.
quoted from L<http://json-rpc.org/wd/JSON-RPC-1-1-WD-2006
le was in JSON package on CPAN before.
Now its interfaces was completely changed.
The old modules - L<JSONRPC::Transport::HTTP> and L<Apache::JSONRPC> are deprecated.
Please try to use JSON::RPC::Ser
package JSON::RPC::Parser;
use strict;
use JSON::RPC::Procedure;
use Carp ();
use Plack::Request;
use Class::Accessor::Lite
new => 1,
rw => [ qw(
coder
) ]
;
sub construct_procedu
re {
my $self = shift;
JSON::RPC::Procedure->new( @_ );
}
sub construct_from_req {
my ($self, $req) = @_;
my $method = $req->method;
my $proc;
if ($method eq 'POST') {
my $request = eval { $self->coder->decode( $req->content ) };
if ($@) {
Carp::croak( "JSON parse error: $@" );
}
my $ref = ref $request;
if ($ref ne 'ARRAY') {
# is no
package JSON::RPC::Test;
use strict;
use parent qw(Exporter);
our @EXPORT = qw(test_rpc);
sub test_rpc {
if (ref $_[0] && @_ == 2) {
@_ = (dispatch => $_[0], client => $_[1]);
}
;
goto \&Plack::Test::test_psgi;
}
1;
=head1 NAME
JSON::RPC::Test - Simple Wrapper To Test Your JSON::RPC
=head1 SYNOPSIS
use JSON::RPC::Test;
test_rpc $dispatch, sub {
...
##########
# JSONRPC version 1.1
# http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
##############################################################################
use strict;
use JSON ();
use Car
#####################
package JSON::RPC::Legacy::Client;
$JSON::RPC::Legacy::Client::VERSION = '1.06';
use LWP::UserAgent;
BEGIN {
for my $method (qw/uri ua json content_type version id allow
od};
}
|;
}
}
sub AUTOLOAD {
my $self = shift;
my $method = $JSON::RPC::Legacy::Client::AUTOLOAD;
$method =~ s/.*:://;
return if ($method eq 'DESTROY');
##################
package JSON::RPC::Legacy::Server::Daemon;
use strict;
use JSON::RPC::Legacy::Server; # for old Perl 5.005
use base qw(JSON::RPC::Legacy::Server);
$JSON::RPC::Legacy::Server::Daem
last;
}
$c->close;
}
}
sub retrieve_json_from_post {
return $_[0]->request->content;
}
sub retrieve_json_from_get {
}
sub response {
my ($self, $response) = @_;
=head1 NAME
JSON::RPC::Legacy::Server::Daemon - JSON-RPC sever for daemon
=head1 SYNOPSIS
# Daemon version
#--------------------------
# In your daemon server script
use JSON::RPC::Legacy::S
########################################
package JSON::RPC::Legacy::Server::Apache2;
use strict;
use lib qw(/var/www/cgi-bin/json/);
use base qw(JSON::RPC::Legacy::Server);
use Apache2::Const -comp
:Table ();
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
$JSON::RPC::Legacy::Server::Apache::VERSION = '1.06';
sub handler {
my($r) = @_;
my $s = __P
Const::OK;
}
sub new {
my $class = shift;
return $class->SUPER::new();
}
sub retrieve_json_from_post {
my $self = shift;
my $r = $self->request;
my $len = $r->headers_in()-
package JSON::RPC::Legacy::Procedure;
#
# http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
#
$JSON::RPC::Legacy::Procedure::VERSION = '1.06';
use strict;
use attributes;
use Carp ();
my $Proce
|Nil|None/) {
Carp::croak("Invalid type '$attr'. Specify 'Parivate' or 'Public' or One of JSONRPC Return Types.");
}
if ($ret_type ne 'Private' and defined $args) {
$Procedure
};
}
1;
__END__
=pod
=head1 NAME
JSON::RPC::Legacy::Procedure - JSON-RPC Service attributes
=head1 SYNOPSIS
package MyApp;
use base ('JSON::RPC::Legacy::Procedure');
sub sum : Pub
##########
# JSONRPC version 1.1
# http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
##############################################################################
use strict;
use JSON ();
use Car
ackage JSON::RPC::Legacy::Server;
my $JSONRPC_Procedure_Able;
BEGIN {
if ($] >= 5.006) {
require JSON::RPC::Legacy::Procedure;
$JSONRPC_Procedure_Able = 1;
}
}
$JSON::RPC:
:Legacy::Server::VERSION = '1.06';
BEGIN {
for my $method (qw/request path_info json version error_message max_length charset content_type
error_response_header return_di
package JSON::RPC::Dispatch;
use strict;
use JSON::RPC::Constants qw(:all);
use JSON::RPC::Parser;
use JSON::RPC::Procedure;
use Router::Simple;
use Scalar::Util;
use Try::Tiny;
use Class::Accessor::
if (! $self->{coder}) {
require JSON;
$self->{coder} = JSON->new->utf8;
}
if (! $self->{parser}) {
$self->{parser} = JSON::RPC::Parser->new( coder => $self->coder )
et_handler {
my ($self, $klass) = @_;
if ( Scalar::Util::blessed( $klass )){
if (JSONRPC_DEBUG > 1) {
warn "Handler is already object : $klass";
}
return $