| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer::RPCPlugin::CallbackResult; |
|
2
|
8
|
|
|
8
|
|
74772
|
use v5.10.1; |
|
|
8
|
|
|
|
|
36
|
|
|
3
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
175
|
|
|
4
|
8
|
|
|
8
|
|
39
|
use strict; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
164
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
33
|
use Exporter 'import'; |
|
|
8
|
|
|
|
|
13
|
|
|
|
8
|
|
|
|
|
384
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/ callback_success callback_fail /; |
|
8
|
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
2579
|
use Types::Standard qw/ Int Str /; |
|
|
8
|
|
|
|
|
466842
|
|
|
|
8
|
|
|
|
|
85
|
|
|
10
|
8
|
|
|
8
|
|
8966
|
use Params::ValidationCompiler qw/ validation_for /; |
|
|
8
|
|
|
|
|
109127
|
|
|
|
8
|
|
|
|
|
2020
|
|
|
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
|
229
|
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
|
602
|
my %data = validation_for( |
|
69
|
|
|
|
|
|
|
params => { |
|
70
|
|
|
|
|
|
|
error_code => { optional => 0, type => Int }, |
|
71
|
|
|
|
|
|
|
error_message => { optional => 0, type => Str }, |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
)->(@_); |
|
74
|
3
|
|
|
|
|
3993
|
return Dancer::RPCPlugin::CallbackResult::Fail->new(%data); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
78
|
23
|
|
|
23
|
|
135
|
my $self = shift; |
|
79
|
23
|
|
|
|
|
141
|
(my $attribute = our $AUTOLOAD) =~ s/.*:://; |
|
80
|
23
|
100
|
|
|
|
332
|
return $self->{$attribute} if exists $self->{$attribute}; |
|
81
|
1
|
|
|
|
|
9
|
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
|
|
82
|
use overload '""' => sub { "success" }; |
|
|
8
|
|
|
1
|
|
19
|
|
|
|
8
|
|
|
|
|
65
|
|
|
|
1
|
|
|
|
|
812
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub new { |
|
101
|
17
|
|
|
17
|
|
55
|
my $class = shift; |
|
102
|
17
|
50
|
|
|
|
71
|
die "No arguments allowed\n" if @_; |
|
103
|
17
|
|
|
|
|
87
|
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
|
|
1293
|
use overload '""' => sub { "fail ($_[0]->{error_code} => $_[0]->{error_message})" }; |
|
|
8
|
|
|
1
|
|
19
|
|
|
|
8
|
|
|
|
|
75
|
|
|
|
1
|
|
|
|
|
639
|
|
|
127
|
8
|
|
|
8
|
|
454
|
use Types::Standard qw/ Int Str /; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
67
|
|
|
128
|
8
|
|
|
8
|
|
5141
|
use Params::ValidationCompiler 'validation_for'; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
1207
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub new { |
|
131
|
3
|
|
|
3
|
|
14
|
my $class = shift; |
|
132
|
3
|
|
|
|
|
20
|
my %data = validation_for( |
|
133
|
|
|
|
|
|
|
params => { |
|
134
|
|
|
|
|
|
|
error_code => {type => Int, optional => 0}, |
|
135
|
|
|
|
|
|
|
error_message => {type => Str, optional => 0}, |
|
136
|
|
|
|
|
|
|
}, |
|
137
|
|
|
|
|
|
|
)->(@_); |
|
138
|
3
|
|
|
|
|
3690
|
return bless {success => 0, %data}, $class; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
(c) MMXVI - Abe Timmerman <abeltje@cpan.org> |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |