line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::RPCPlugin::DispatchFromConfig; |
2
|
21
|
|
|
21
|
|
57801
|
use Moo; |
|
21
|
|
|
|
|
7188
|
|
|
21
|
|
|
|
|
120
|
|
3
|
|
|
|
|
|
|
|
4
|
21
|
|
|
21
|
|
6740
|
use Dancer2::RPCPlugin::DispatchItem; |
|
21
|
|
|
|
|
56
|
|
|
21
|
|
|
|
|
467
|
|
5
|
21
|
|
|
21
|
|
122
|
use Scalar::Util 'blessed'; |
|
21
|
|
|
|
|
40
|
|
|
21
|
|
|
|
|
10102
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has plugin_object => ( |
8
|
|
|
|
|
|
|
is => 'ro', |
9
|
|
|
|
|
|
|
isa => sub { blessed($_[0]) }, |
10
|
|
|
|
|
|
|
required => 1, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
has plugin => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => sub { $_[0] =~ qr/^(?:jsonrpc|restrpc|xmlrpc)$/ }, |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
has config => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { ref($_[0]) eq 'HASH' }, |
20
|
|
|
|
|
|
|
required => 1, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
has endpoint => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => sub { $_[0] && !ref($_[0]) }, |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub build_dispatch_table { |
29
|
4
|
|
|
4
|
1
|
393
|
my $self = shift; |
30
|
4
|
|
|
|
|
30
|
my $app = $self->plugin_object->app; |
31
|
4
|
|
|
|
|
224
|
my $config = $self->config->{ $self->endpoint }; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
17
|
my @packages = keys %$config; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
7
|
my $dispatch; |
36
|
4
|
|
|
|
|
10
|
for my $package (@packages) { |
37
|
4
|
|
|
|
|
227
|
eval "require $package"; |
38
|
4
|
100
|
|
|
|
22
|
if (my $error = $@) { |
39
|
1
|
|
|
|
|
8
|
$app->log(error => "Cannot load '$package': $error"); |
40
|
1
|
|
|
|
|
74
|
die "Cannot load $package ($error) in build_dispatch_table_from_config\n"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
6
|
my @rpc_methods = keys %{ $config->{$package} }; |
|
3
|
|
|
|
|
11
|
|
44
|
3
|
|
|
|
|
7
|
for my $rpc_method (@rpc_methods) { |
45
|
4
|
|
|
|
|
919
|
my $subname = $config->{$package}{$rpc_method}; |
46
|
4
|
|
|
|
|
8
|
$app->log( |
47
|
4
|
|
|
|
|
40
|
debug => "[bdfc] @{[$self->endpoint]}: $rpc_method => $subname" |
48
|
|
|
|
|
|
|
); |
49
|
4
|
100
|
|
|
|
274
|
if (my $handler = $package->can($subname)) { |
50
|
3
|
|
|
|
|
30
|
$dispatch->{$rpc_method} = Dancer2::RPCPlugin::DispatchItem->new( |
51
|
|
|
|
|
|
|
package => $package, |
52
|
|
|
|
|
|
|
code => $handler |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
1
|
|
|
|
|
9
|
die "Handler not found for $rpc_method: $package\::$subname doesn't seem to exist.\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
928
|
my $dispatch_dump = do { |
62
|
2
|
|
|
|
|
389
|
require Data::Dumper; |
63
|
2
|
|
|
|
|
5299
|
local ($Data::Dumper::Indent, $Data::Dumper::Sortkeys, $Data::Dumper::Terse) = (0, 1, 1); |
64
|
2
|
|
|
|
|
9
|
Data::Dumper::Dumper($dispatch); |
65
|
|
|
|
|
|
|
}; |
66
|
2
|
|
|
|
|
188
|
$app->log( |
67
|
|
|
|
|
|
|
debug => "[dispatch_table_from_config]->{$self->plugin} ", $dispatch_dump |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
160
|
return $dispatch; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Dancer2::RPCPlugin::DispatchFromConfig - Build dispatch-table from the Dancer Config |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use Dancer2::RPCPlugin::DispatchFromConfig; |
84
|
|
|
|
|
|
|
sub dispatch_call { |
85
|
|
|
|
|
|
|
my $config = plugin_setting(); |
86
|
|
|
|
|
|
|
my $dtb = Dancer2::RPCPlugin::DispatchFromConfig->new( |
87
|
|
|
|
|
|
|
... |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
return $dtb->build_dispatch_table(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 $dtb->new(\%parameters) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head3 Parameters |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Named, list: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item plugin_object => $plugin |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item plugin => <xmlrpc|jsonrpc|jsonrpc> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item config => $config_from_plugin |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item endpoint => $endpoint |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head3 Responses |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
An instantiated object. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 $dtb->build_dispatch_table() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head3 Parameters |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
None |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 Responses |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
A hashref of rpc-method names as key and L<Dancer2::RPCPlugin::DispatchItem> |
125
|
|
|
|
|
|
|
objects as values. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 COPYRIGHT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
(c) MMXV - Abe Timmerman <abeltje@cpan.org> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |