-
-
24 Feb 2021 11:04:26 UTC
- Distribution: MojoX-JSON-RPC
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (9)
- Testers (211 / 0 / 0)
- Kwalitee
Bus factor: 1- 80.90% Coverage
- License: artistic_2
- Activity
24 month- Tools
- Download (16.59KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Henry Tang
- Dependencies
- Mojolicious
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
MojoX::JSON::RPC::Service - JSON RPC Service registration
SYNOPSIS
use MojoX::JSON::RPC::Service; my $svc = MojoX::JSON::RPC::Service->new; $svc->register( 'sum', sub { my @params = @_; my $sum = 0; $sum += $_ for @params; return $sum; } ); $svc->register( 'remote_address', sub { my $tx = shift; return $tx->remote_address; }, { with_mojo_tx => 1 } ); ## Then in Mojolicious application $self->plugin( 'json_rpc_dispatcher', services => { '/jsonrpc' => $svc, } );
This package can also be used as a base class to make it easy to create object-oriented JSON-RPC applications:
package MyService; use Mojo::Base 'MojoX::JSON::RPC::Service'; sub sum { my ($self, @params) = @_; my $sum = 0; $sum += $_ for @params; return $sum; } __PACKAGE__->register_rpc_method_names( 'sum' ); ## Then in Mojolicious application $self->plugin( 'json_rpc_dispatcher', services => { '/jsonrpc' => MyService->new, } );
DESCRIPTION
Register JSON-RPC service calls.
METHODS
MojoX::JSON::RPC::Service inherits all methods from Mojo::Base and implements the following new ones.
register
Register RPC methods.
$svc->register( 'sum', sub { my @params = @_; my $sum = 0; $sum += $_ for @params; return $sum; } );
with_mojo_tx can be passed as options. In that case, Mojo::Transaction object will be pass as first argument of the subroutine.
$svc->register( 'remote_address', sub { my $tx = shift; return $tx->remote_address; }, { with_mojo_tx => 1 } );
register_rpc_method_names
Class method. Register a list of methods as JSON-RPC calls.
__PACKAGE__->register_rpc_method_names( 'sum', 'multiply' );
SEE ALSO
Module Install Instructions
To install MojoX::JSON::RPC, copy and paste the appropriate command in to your terminal.
cpanm MojoX::JSON::RPC
perl -MCPAN -e shell install MojoX::JSON::RPC
For more information on module installation, please visit the detailed CPAN module installation guide.