line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::DispatchMethodList; |
2
|
22
|
|
|
22
|
|
56916
|
use warnings; |
|
22
|
|
|
|
|
46
|
|
|
22
|
|
|
|
|
663
|
|
3
|
22
|
|
|
22
|
|
111
|
use strict; |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
475
|
|
4
|
|
|
|
|
|
|
|
5
|
22
|
|
|
22
|
|
626
|
use Params::ValidationCompiler 'validation_for'; |
|
22
|
|
|
|
|
20809
|
|
|
22
|
|
|
|
|
971
|
|
6
|
22
|
|
|
22
|
|
794
|
use Types::Standard qw/ Str StrMatch ArrayRef Int /; |
|
22
|
|
|
|
|
116207
|
|
|
22
|
|
|
|
|
173
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Dancer2::RPCPlugin::DispatchMethodList - Class for maintaining a global methodlist. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Dancer2::RPCPlugin::DispatchMethodList; |
15
|
|
|
|
|
|
|
my $methods = Dancer2::RPCPlugin::DispatchMethodList->new(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$methods->set_partial( |
18
|
|
|
|
|
|
|
protocol => <jsonrpc|restrpc|xmlrpc>, |
19
|
|
|
|
|
|
|
endpoint => </configured>, |
20
|
|
|
|
|
|
|
methods => [ @method_names ], |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Somewhere else |
24
|
|
|
|
|
|
|
my $dml = Dancer2::RPCPlugin::DispatchMethodList->new(); |
25
|
|
|
|
|
|
|
my $methods = $dml->list_methods(<any|jsonrpc|restrpc|xmlrpc>); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This class implements a singleton that can hold the collection of all method names. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 my $dml = Dancer2::RPCPlugin::DispatchMethodList->new() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head3 Parameters |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
None! |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head3 Responses |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$singleton = bless $parameters, $class; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $_singleton; |
44
|
|
|
|
|
|
|
sub new { |
45
|
32
|
100
|
|
32
|
1
|
1199
|
return $_singleton if $_singleton; |
46
|
|
|
|
|
|
|
|
47
|
20
|
|
|
|
|
52
|
my $class = shift; |
48
|
20
|
|
|
|
|
110
|
$_singleton = bless {protocol => {}}, $class; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 $dml->set_partial(%parameters) |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head3 Parameters |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Named, list: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item protocol => <jsonrpc|restrpc|xmlrpc> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item endpoint => $endpoint |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item methods => \@method_list |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 Responses |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$self |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub set_partial { |
74
|
27
|
|
|
27
|
1
|
476
|
my $self = shift; |
75
|
27
|
|
|
|
|
261
|
my %args = validation_for( |
76
|
|
|
|
|
|
|
params => { |
77
|
|
|
|
|
|
|
protocol => {type => StrMatch[ qr/^(?:json|xml|rest)rpc$/], optional => 0}, |
78
|
|
|
|
|
|
|
endpoint => {type => StrMatch[ qr/^.*$/] , optional => 0}, |
79
|
|
|
|
|
|
|
methods => {type => ArrayRef}, |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
)->(@_); |
82
|
27
|
|
|
|
|
73053
|
$self->{protocol}{$args{protocol}}{$args{endpoint}} = $args{methods}; |
83
|
27
|
|
|
|
|
2612
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 $dml->list_methods(@parameters) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Method that returns information about the dispatch-table. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head3 Parameters |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Positional, list: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item $protocol => undef || <any|jsonrpc|restrpc|xmlrpc> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head3 Responses |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
In case of no C<$protocol>: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
xmlrpc => { |
106
|
|
|
|
|
|
|
$endpoint1 => [ list ], |
107
|
|
|
|
|
|
|
$endpoint2 => [ list ], |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
jsonrpc => { |
110
|
|
|
|
|
|
|
$endpoint1 => [ list ], |
111
|
|
|
|
|
|
|
$endpoint2 => [ list ], |
112
|
|
|
|
|
|
|
}, |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
In case of specified C<$protocol>: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
$endpoint1 => [ list ], |
119
|
|
|
|
|
|
|
$endpoint2 => [ list ], |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub list_methods { |
125
|
9
|
|
|
9
|
1
|
32
|
my $self = shift; |
126
|
9
|
|
|
|
|
67
|
my ($protocol) = validation_for( |
127
|
|
|
|
|
|
|
params => [ |
128
|
|
|
|
|
|
|
{ |
129
|
|
|
|
|
|
|
type => StrMatch [qr/^(?:any|(?:json|rest|xml)rpc)$/], |
130
|
|
|
|
|
|
|
default => 'any', |
131
|
|
|
|
|
|
|
}, |
132
|
|
|
|
|
|
|
] |
133
|
|
|
|
|
|
|
)->(@_); |
134
|
9
|
100
|
|
|
|
13378
|
if ($protocol eq 'any') { |
135
|
3
|
|
|
|
|
158
|
return $self->{protocol}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
6
|
|
|
|
|
334
|
return $self->{protocol}{$protocol}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
(c) MMXVI - Abe Timmerman <abeltje@cpan.org> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |