| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::CallbackResult::Factory; |
|
2
|
20
|
|
|
20
|
|
54658
|
use warnings; |
|
|
20
|
|
|
|
|
43
|
|
|
|
20
|
|
|
|
|
572
|
|
|
3
|
20
|
|
|
20
|
|
98
|
use strict; |
|
|
20
|
|
|
|
|
94
|
|
|
|
20
|
|
|
|
|
398
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
93
|
use Exporter 'import'; |
|
|
20
|
|
|
|
|
78
|
|
|
|
20
|
|
|
|
|
870
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/ callback_success callback_fail /; |
|
7
|
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
4938
|
use Params::ValidationCompiler 'validation_for'; |
|
|
20
|
|
|
|
|
236857
|
|
|
|
20
|
|
|
|
|
1026
|
|
|
9
|
20
|
|
|
20
|
|
465
|
use Types::Standard qw/ Int Str /; |
|
|
20
|
|
|
|
|
50756
|
|
|
|
20
|
|
|
|
|
379
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Dancer2::RPCPlugin::CallbackResult - Factory for generating Callback-results. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Dancer2::Plugin::RPC::JSON; |
|
18
|
|
|
|
|
|
|
use Dancer2::RPCPlugin::CallbackResult; |
|
19
|
|
|
|
|
|
|
jsonrpc '/admin' => { |
|
20
|
|
|
|
|
|
|
publish => 'config', |
|
21
|
|
|
|
|
|
|
callback => sub { |
|
22
|
|
|
|
|
|
|
my ($request, $rpc_method) = @_; |
|
23
|
|
|
|
|
|
|
if ($rpc_method =~ qr/^admin\.\w+$/) { |
|
24
|
|
|
|
|
|
|
return callback_success(); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
return callback_fail( |
|
27
|
|
|
|
|
|
|
error_code => -32768, |
|
28
|
|
|
|
|
|
|
error_message => "only admin methods allowed: $rpc_method", |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
}, |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 callback_success() |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Allows no arguments. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns an instantiated L<Dancer::RPCPlugin::CallbackResult::Success> object. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub callback_success { |
|
44
|
21
|
50
|
|
21
|
1
|
1037
|
die "callback_success() does not have arguments\n" if @_ > 1; |
|
45
|
21
|
|
|
|
|
303
|
return Dancer2::RPCPlugin::CallbackResult::Success->new(); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 callback_fail(%arguments) |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Allows these named arguments: |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item error_code => $code |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item error_message => $message |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=back |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns an instantiated L<Dancer::RPCPlugin::CallbackResult::Fail> object. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub callback_fail { |
|
65
|
3
|
|
|
3
|
1
|
2202
|
my %data = validation_for( |
|
66
|
|
|
|
|
|
|
params => { |
|
67
|
|
|
|
|
|
|
error_code => {optional => 0, type => Int}, |
|
68
|
|
|
|
|
|
|
error_message => {optional => 0, type => Str}, |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
)->(@_); |
|
71
|
3
|
|
|
|
|
3753
|
return Dancer2::RPCPlugin::CallbackResult::Fail->new(%data); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::CallbackResult; |
|
77
|
20
|
|
|
20
|
|
19918
|
use Moo; |
|
|
20
|
|
|
|
|
6958
|
|
|
|
20
|
|
|
|
|
196
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Dancer2::RPCPlugin::CallbackResult - Base class for callback-result. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use overload ( |
|
86
|
2
|
|
|
2
|
|
1433
|
'""' => sub { $_[0]->_as_string }, |
|
87
|
20
|
|
|
|
|
131
|
fallback => 1, |
|
88
|
20
|
|
|
20
|
|
7389
|
); |
|
|
20
|
|
|
|
|
49
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::CallbackResult::Success; |
|
93
|
20
|
|
|
20
|
|
1400
|
use Moo; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
82
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
extends 'Dancer2::RPCPlugin::CallbackResult'; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has success => ( |
|
98
|
|
|
|
|
|
|
is => 'ro', |
|
99
|
|
|
|
|
|
|
isa => sub { $_[0] == 1 }, |
|
100
|
|
|
|
|
|
|
default => 1, |
|
101
|
|
|
|
|
|
|
); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Dancer2::RPCPlugin::CallbackResult::Success - Class for success |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 new() |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Constructor, does not allow any arguments. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 success() |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Returns 1; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _as_string { |
|
120
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
121
|
1
|
|
|
|
|
4
|
return "success"; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::CallbackResult::Fail; |
|
127
|
20
|
|
|
20
|
|
5797
|
use Moo; |
|
|
20
|
|
|
|
|
47
|
|
|
|
20
|
|
|
|
|
62
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
extends 'Dancer2::RPCPlugin::CallbackResult'; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Dancer2::RPCPlugin::CallbackResult::Fail - Class for failure |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 new() |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Constructor, allows named arguments: |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item error_code => $code |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item error_message => $message |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
has error_code => ( |
|
150
|
|
|
|
|
|
|
is => 'ro', |
|
151
|
|
|
|
|
|
|
isa => sub { $_[0] =~ /^[+-]?\d+$/ }, |
|
152
|
|
|
|
|
|
|
required => 1, |
|
153
|
|
|
|
|
|
|
); |
|
154
|
|
|
|
|
|
|
has error_message => ( |
|
155
|
|
|
|
|
|
|
is => 'ro', |
|
156
|
|
|
|
|
|
|
required => 1, |
|
157
|
|
|
|
|
|
|
); |
|
158
|
|
|
|
|
|
|
has success => ( |
|
159
|
|
|
|
|
|
|
is => 'ro', |
|
160
|
|
|
|
|
|
|
isa => sub { $_[0] == 0 }, |
|
161
|
|
|
|
|
|
|
default => 0, |
|
162
|
|
|
|
|
|
|
); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _as_string { |
|
165
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
166
|
1
|
|
|
|
|
10
|
return sprintf("fail (%s => %s)", $self->error_code, $self->error_message); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
(c) MMXVI - Abe Timmerman <abeltje@cpan.org> |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |