Dancer2-Plugin-RPC
view release on metacpan or search on metacpan
lib/Dancer2/Plugin/RPC.pm view on Meta::CPAN
package Dancer2::Plugin::RPC;
use strict;
use warnings;
use v5.10.1;
our $VERSION = '2.02';
=head1 NAME
Dancer2::Plugin::RPC - Namespace for XMLRPC, JSONRPC2 and RESTRPC plugins
=head1 DESCRIPTION
This module contains plugins for L<Dancer2>: L<Dancer2::Plugin::RPC::XMLRPC>,
L<Dancer2::Plugin::RPC::JSONRPC> and L<Dancer2::Plugin::RPC::RESTRPC>.
=head2 Dancer2::Plugin::RPC::XMLRPC
This plugin exposes the new keyword C<xmlrpc> that is followed by 2 arguments:
the endpoint and the arguments to configure the xmlrpc-calls at this endpoint.
=head2 Dancer2::Plugin::RPC::JSONRPC
This plugin exposes the new keyword C<jsonrpc> that is followed by 2 arguments:
the endpoint and the arguments to configure the jsonrpc-calls at this endpoint.
=head2 Dancer2::Plugin::RPC::RESTRPC
This plugin exposes the new keyword C<restrpc> that is followed by 2 arguments:
the endpoint and the arguments to configure the restrpc-calls at this endpoint.
=head2 General arguments to xmlrpc/jsonrpc/restrpc
The dispatch table is build by endpoint.
=head3 publish => <config|pod|$coderef>
=over
=item publish => B<config>
The dispatch table is build from the YAML-config:
plugins:
'RPC::XMLRPC':
'/endpoint1':
'Module::Name1':
method1: sub1
method2: sub2
'Module::Name2':
method3: sub3
'/endpoint2':
'Module::Name3':
method4: sub4
The B<arguments> argument should be empty for this publishing type.
=item publish => B<pod>
The dispatch table is build by parsing the POD for C<=for xmlrpc>,
C<=for jsonrpc> or C<=for restrpc>.
=for xmlrpc <method_name> <sub_name> [<base_dir>]
The B<arguments> argument must be an Arrayref with module names. The
POD-directive must be in the same file as the code!
=item publish => B<$coderef>
With this publishing type, you will need to build your own dispatch table and return it.
use Dancer2::RPCPlugin::DispatchItem;
return {
method1 => Dancer2::RPCPlugin::DispatchItem->new(
package => 'Module::Name1',
code => Module::Name1->can('sub1'),
),
method2 => Dancer2::RPCPlugin::DispatchItem->new(
package => 'Module::Name1',
code => Module::Name1->can('sub2'),
),
method3 => Dancer2::RPCPlugin::DispatchItem->new(
pacakage => 'Module::Name2',
code => Module::Name2->can('sub3'),
),
};
=back
=head3 arguments => $list
This argumument is needed for publishing type B<pod> and must be a list of
module names that contain the pod (and code).
=head3 callback => $coderef
The B<callback> argument may contain a C<$coderef> that does additional checks
and should return a L<Dancer2::RPCPlugin::CallbackResult> object.
$callback->($request, $method_name, @method_args);
Returns for success: C<< callback_success() >>
Returns for failure: C<< callback_fail(error_code => $code, error_message => $msg) >>
This is useful for ACL checking.
=head3 code_wrapper => $coderef
The B<code_wrapper> argument can be used to wrap the code (from the dispatch table).
my $wrapper = sub {
( run in 0.765 second using v1.01-cache-2.11-cpan-d7f47b0818f )