line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::RPCPlugin::DispatchFromConfig; |
2
|
8
|
|
|
8
|
|
235090
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
266
|
|
3
|
8
|
|
|
8
|
|
44
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
152
|
|
4
|
8
|
|
|
8
|
|
31
|
use Exporter 'import'; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
435
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw/dispatch_table_from_config/; |
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
45
|
use Dancer qw/error warning info debug/; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
67
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
10859
|
use Dancer::RPCPlugin::DispatchItem; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
349
|
|
10
|
8
|
|
|
8
|
|
1869
|
use Dancer::RPCPlugin::PluginNames; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
217
|
|
11
|
8
|
|
|
8
|
|
40
|
use Types::Standard qw/ Int Str StrMatch Any /; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
42
|
|
12
|
8
|
|
|
8
|
|
6106
|
use Params::ValidationCompiler 'validation_for'; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
2521
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub dispatch_table_from_config { |
15
|
14
|
|
|
14
|
1
|
250
|
my $pn_re = Dancer::RPCPlugin::PluginNames->new->regex; |
16
|
14
|
|
|
|
|
297
|
my %args = validation_for( |
17
|
|
|
|
|
|
|
params => { |
18
|
|
|
|
|
|
|
plugin => { type => StrMatch[ qr/^$pn_re$/ ] }, |
19
|
|
|
|
|
|
|
config => { type => Any }, |
20
|
|
|
|
|
|
|
endpoint => { type => Str, optional => 0 }, |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
)->(@_); |
23
|
14
|
|
|
|
|
27790
|
my $config = $args{config}{ $args{endpoint} }; |
24
|
|
|
|
|
|
|
|
25
|
14
|
|
|
|
|
763
|
my @pkgs = keys %$config; |
26
|
|
|
|
|
|
|
|
27
|
14
|
|
|
|
|
31
|
my $dispatch; |
28
|
14
|
|
|
|
|
48
|
for my $pkg (@pkgs) { |
29
|
5
|
50
|
|
|
|
272
|
eval "require $pkg" if $pkg ne 'main'; |
30
|
5
|
50
|
|
|
|
541
|
error("Loading $pkg: $@") if $@; |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
13
|
my @rpc_methods = keys %{ $config->{$pkg} }; |
|
5
|
|
|
|
|
23
|
|
33
|
5
|
|
|
|
|
16
|
for my $rpc_method (@rpc_methods) { |
34
|
9
|
|
|
|
|
23
|
my $subname = $config->{$pkg}{$rpc_method}; |
35
|
9
|
|
|
|
|
55
|
debug("[bdfc] $args{endpoint}: $rpc_method => $subname"); |
36
|
9
|
100
|
|
|
|
526
|
if (my $handler = $pkg->can($subname)) { |
37
|
8
|
|
|
|
|
33
|
$dispatch->{$rpc_method} = dispatch_item( |
38
|
|
|
|
|
|
|
package => $pkg, |
39
|
|
|
|
|
|
|
code => $handler |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
1
|
|
|
|
|
11
|
die "Handler not found for $rpc_method: $pkg\::$subname doesn't seem to exist.\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# we don't want "Encountered CODE ref, using dummy placeholder" |
49
|
|
|
|
|
|
|
# thus we use Data::Dumper::Dumper() directly. |
50
|
13
|
|
|
|
|
55
|
local ($Data::Dumper::Indent, $Data::Dumper::Sortkeys, $Data::Dumper::Terse) = (0, 1, 1); |
51
|
13
|
|
|
|
|
81
|
debug( |
52
|
|
|
|
|
|
|
"[build_dispatcher_from_config]->{$args{plugin}} ", |
53
|
|
|
|
|
|
|
Data::Dumper::Dumper($dispatch) |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
13
|
|
|
|
|
1042
|
return $dispatch; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Dancer::RPCPlugin::DispatchFromConfig - Build dispatch-table from the Dancer Config |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Dancer::Plugin; |
68
|
|
|
|
|
|
|
use Dancer::RPCPlugin::DispatchFromConfig; |
69
|
|
|
|
|
|
|
sub dispatch_call { |
70
|
|
|
|
|
|
|
my $config = plugin_setting(); |
71
|
|
|
|
|
|
|
return dispatch_table_from_config($config); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 dispatch_table_from_config(%arguments) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head3 Parameters |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Named: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item plugin => <xmlrpc|jsonrpc|restrpc> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item config => $config_from_plugin |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item endpoint => '/endpoint_for_dispatch_table' |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head3 Responses |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
A (partial) dispatch-table. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
(c) MMXV - Abe Timmerman <abeltje@cpan.org> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |