File Coverage

blib/lib/Dancer2/Plugin/RPC.pm
Criterion Covered Total %
statement 2 2 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 3 3 100.0


line stmt bran cond sub pod time code
1             package Dancer2::Plugin::RPC;
2 20     20   259 use v5.10;
  20         68  
3              
4             our $VERSION = '2.00_01';
5              
6             =head1 NAME
7              
8             Dancer2::Plugin::RPC - Namespace for XMLRPC, JSONRPC2 and RESTRPC plugins
9              
10             =head1 DESCRIPTION
11              
12             This module contains plugins for L<Dancer2>: L<Dancer2::Plugin::RPC::XML>,
13             L<Dancer2::Plugin::RPC::JSON> and L<Dancer2::Plugin::RPC::REST>.
14              
15             =head2 Dancer2::Plugin::RPC::XML
16              
17             This plugin exposes the new keyword C<xmlrpc> that is followed by 2 arguments:
18             the endpoint and the arguments to configure the xmlrpc-calls at this endpoint.
19              
20             =head2 Dancer2::Plugin::RPC::JSON
21              
22             This plugin exposes the new keyword C<jsonrpc> that is followed by 2 arguments:
23             the endpoint and the arguments to configure the jsonrpc-calls at this endpoint.
24              
25             =head2 Dancer2::Plugin::RPC::REST
26              
27             This plugin exposes the new keyword C<restrpc> that is followed by 2 arguments:
28             the endpoint and the arguments to configure the restrpc-calls at this endpoint.
29              
30             =head2 General arguments to xmlrpc/jsonrpc/restrpc
31              
32             The dispatch table is build by endpoint.
33              
34             =head3 publish => <config|pod|$coderef>
35              
36             =over
37              
38             =item publish => B<config>
39              
40             The dispatch table is build from the YAML-config:
41              
42             plugins:
43             'RPC::XML':
44             '/endpoint1':
45             'Module::Name1':
46             method1: sub1
47             method2: sub2
48             'Module::Name2':
49             method3: sub3
50             '/endpoint2':
51             'Module::Name3':
52             method4: sub4
53              
54             The B<arguments> argument should be empty for this publishing type.
55              
56             =item publish => B<pod>
57              
58             The dispatch table is build by parsing the POD for C<=for xmlrpc>,
59             C<=for jsonrpc> or C<=for restrpc>.
60              
61             =for xmlrpc <method_name> <sub_name>
62              
63             The B<arguments> argument must be an Arrayref with module names. The
64             POD-directive must be in the same file as the code!
65              
66             =item publish => B<$coderef>
67              
68             With this publishing type, you will need to build your own dispatch table and return it.
69              
70             use Dancer2::RPCPlugin::DispatchItem;
71             return {
72             method1 => dispatch_item(
73             package => 'Module::Name1',
74             code => Module::Name1->can('sub1'),
75             ),
76             method2 => dispatch_item(
77             package => 'Module::Name1',
78             code => Module::Name1->can('sub2'),
79             ),
80             method3 => dispatch_item(
81             pacakage => 'Module::Name2',
82             code => Module::Name2->can('sub3'),
83             ),
84             };
85              
86             =back
87              
88             =head3 arguments => $list
89              
90             This argumument is needed for publishing type B<pod> and must be a list of
91             module names that contain the pod (and code).
92              
93             =head3 callback => $coderef
94              
95             The B<callback> argument may contain a C<$coderef> that does additional checks
96             and should return a L<Dancer2::RPCPlugin::CallbackResult> object.
97              
98             $callback->($request, $method_name, @method_args);
99              
100             Returns for success: C<< callback_success() >>
101              
102             Returns for failure: C<< callback_fail(error_code => $code, error_message => $msg) >>
103              
104             This is useful for ACL checking.
105              
106             =head3 code_wrapper => $coderef
107              
108             The B<code_wrapper> argument can be used to wrap the code (from the dispatch table).
109              
110             my $wrapper = sub {
111             my $code = shift;
112             my $pkg = shift;
113             my $method = shift;
114             my $instance = $pkg->new();
115             $instance->$code(@_);
116             };
117              
118             =head1 LICENSE
119              
120             This library is free software; you can redistribute it and/or modify
121             it under the same terms as Perl itself.
122              
123             See:
124              
125             =over 4
126              
127             =item * L<http://www.perl.com/perl/misc/Artistic.html>
128              
129             =item * L<http://www.gnu.org/copyleft/gpl.html>
130              
131             =back
132              
133             This program is distributed in the hope that it will be useful,
134             but WITHOUT ANY WARRANTY; without even the implied warranty of
135             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
136              
137             =head1 AUTHOR
138              
139             (c) MMXVII - Abe Timmerman <abeltje@cpan.org>
140              
141             =cut