line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::RPCPlugin::CallbackResult; |
2
|
8
|
|
|
8
|
|
70108
|
use v5.10.1; |
|
8
|
|
|
|
|
37
|
|
3
|
8
|
|
|
8
|
|
34
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
175
|
|
4
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
164
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
36
|
use Exporter 'import'; |
|
8
|
|
|
|
|
795
|
|
|
8
|
|
|
|
|
436
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/ callback_success callback_fail /; |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
2577
|
use Types::Standard qw/ Int Str /; |
|
8
|
|
|
|
|
476183
|
|
|
8
|
|
|
|
|
73
|
|
10
|
8
|
|
|
8
|
|
8548
|
use Params::ValidationCompiler qw/ validation_for /; |
|
8
|
|
|
|
|
111590
|
|
|
8
|
|
|
|
|
2067
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Dancer::RPCPlugin::CallbackResult - Factory for generating Callback-results. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Dancer::Plugin::RPC::JSONRPC; |
19
|
|
|
|
|
|
|
use Dancer::RPCPlugin::CallbackResult; |
20
|
|
|
|
|
|
|
jsonrpc '/admin' => { |
21
|
|
|
|
|
|
|
publish => 'config', |
22
|
|
|
|
|
|
|
callback => sub { |
23
|
|
|
|
|
|
|
my ($request, $rpc_method) = @_; |
24
|
|
|
|
|
|
|
if ($rpc_method =~ qr/^admin\.\w+$/) { |
25
|
|
|
|
|
|
|
return callback_success(); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
|
|
|
|
|
|
return callback_fail( |
29
|
|
|
|
|
|
|
error_code => -32768, |
30
|
|
|
|
|
|
|
error_message => "only admin methods allowed: $rpc_method", |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 callback_success() |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Allows no arguments. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns an instantiated L<Dancer::RPCPlugin::CallbackResult::Success> object. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub callback_success { |
47
|
17
|
50
|
|
17
|
1
|
294
|
die "callback_success() does not have arguments\n" if @_ > 1; |
48
|
17
|
|
|
|
|
140
|
return Dancer::RPCPlugin::CallbackResult::Success->new(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 callback_fail(%arguments) |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Allows these named arguments: |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item error_code => $code |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item error_message => $message |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Returns an instantiated L<Dancer::RPCPlugin::CallbackResult::Fail> object. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub callback_fail { |
68
|
3
|
|
|
3
|
1
|
1005
|
my %data = validation_for( |
69
|
|
|
|
|
|
|
params => { |
70
|
|
|
|
|
|
|
error_code => { optional => 0, type => Int }, |
71
|
|
|
|
|
|
|
error_message => { optional => 0, type => Str }, |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
)->(@_); |
74
|
3
|
|
|
|
|
4916
|
return Dancer::RPCPlugin::CallbackResult::Fail->new(%data); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub AUTOLOAD { |
78
|
23
|
|
|
23
|
|
255
|
my $self = shift; |
79
|
23
|
|
|
|
|
135
|
(my $attribute = our $AUTOLOAD) =~ s/.*:://; |
80
|
23
|
100
|
|
|
|
348
|
return $self->{$attribute} if exists $self->{$attribute}; |
81
|
1
|
|
|
|
|
14
|
die "Unknown attribute $attribute\n"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
0
|
|
|
sub DESTROY { } |
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 PACKAGE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Dancer::RPCPlugin::CallbackResult::Success - Class for success |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 new() |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Constructor, does not allow any arguments. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package Dancer::RPCPlugin::CallbackResult::Success; |
97
|
|
|
|
|
|
|
our @ISA = ('Dancer::RPCPlugin::CallbackResult'); |
98
|
8
|
|
|
8
|
|
75
|
use overload '""' => sub { "success" }; |
|
8
|
|
|
1
|
|
19
|
|
|
8
|
|
|
|
|
65
|
|
|
1
|
|
|
|
|
1360
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub new { |
101
|
17
|
|
|
17
|
|
53
|
my $class = shift; |
102
|
17
|
50
|
|
|
|
69
|
die "No arguments allowed\n" if @_; |
103
|
17
|
|
|
|
|
78
|
return bless {success => 1}, $class; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 PACKAGE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Dancer::RPCPlugin::CallbackResult::Fail - Class for failure |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 new() |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Constructor, allows named arguments: |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item error_code => $code |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item error_message => $message |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
package Dancer::RPCPlugin::CallbackResult::Fail; |
125
|
|
|
|
|
|
|
our @ISA = ('Dancer::RPCPlugin::CallbackResult'); |
126
|
8
|
|
|
8
|
|
1263
|
use overload '""' => sub { "fail ($_[0]->{error_code} => $_[0]->{error_message})" }; |
|
8
|
|
|
1
|
|
18
|
|
|
8
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
1239
|
|
127
|
8
|
|
|
8
|
|
475
|
use Types::Standard qw/ Int Str /; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
66
|
|
128
|
8
|
|
|
8
|
|
4809
|
use Params::ValidationCompiler 'validation_for'; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
987
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub new { |
131
|
3
|
|
|
3
|
|
15
|
my $class = shift; |
132
|
3
|
|
|
|
|
18
|
my %data = validation_for( |
133
|
|
|
|
|
|
|
params => { |
134
|
|
|
|
|
|
|
error_code => {type => Int, optional => 0}, |
135
|
|
|
|
|
|
|
error_message => {type => Str, optional => 0}, |
136
|
|
|
|
|
|
|
}, |
137
|
|
|
|
|
|
|
)->(@_); |
138
|
3
|
|
|
|
|
4287
|
return bless {success => 0, %data}, $class; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
(c) MMXVI - Abe Timmerman <abeltje@cpan.org> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |