line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::JSON::RPC::Service; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1016950
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
18
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Store rpc methods registered by register_rpc_method_names |
8
|
|
|
|
|
|
|
my $_rpcs = undef; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
4
|
|
|
4
|
1
|
19432
|
my $class = shift; |
12
|
4
|
|
|
|
|
27
|
my $self = $class->SUPER::new(@_); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# make shallow copy of class level rpcs |
15
|
4
|
100
|
100
|
|
|
40
|
if ( ref $_rpcs eq 'HASH' && exists $_rpcs->{$class} ) { |
16
|
1
|
|
|
|
|
2
|
$self->{_rpcs} = { %{ $_rpcs->{$class} } }; |
|
1
|
|
|
|
|
12
|
|
17
|
|
|
|
|
|
|
} |
18
|
4
|
|
|
|
|
30
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub register_rpc_method_names { |
22
|
1
|
|
|
1
|
1
|
93
|
my ( $class, @methods ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
METHOD: |
25
|
1
|
|
|
|
|
2
|
foreach my $m (@methods) { |
26
|
8
|
|
|
|
|
15
|
my $name = $class . '::' . $m; |
27
|
8
|
|
|
|
|
305
|
my $method = eval qq|*{*$name}{CODE}|; |
28
|
|
|
|
|
|
|
|
29
|
8
|
50
|
|
|
|
35
|
if ( ref $method ne 'CODE' ) { |
30
|
0
|
|
|
|
|
0
|
Carp::croak |
31
|
|
|
|
|
|
|
qq{register_rpc_method_names: $name not a method.}; |
32
|
|
|
|
|
|
|
} |
33
|
8
|
50
|
|
|
|
17
|
if ( exists $_rpcs->{$class}->{$m} ) { |
34
|
0
|
|
|
|
|
0
|
Carp::croak |
35
|
|
|
|
|
|
|
qq{register_rpc_method_names: $name already registered.}; |
36
|
|
|
|
|
|
|
} |
37
|
8
|
|
|
|
|
24
|
$_rpcs->{$class}->{$m} = { method => $method, with_svc_obj => 1 }; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
return $class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub register { |
45
|
13
|
|
|
13
|
1
|
26
|
my ( $self, $name, $sub, $options ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
13
|
50
|
33
|
|
|
42
|
if ( !defined $name || $name eq q{} ) { |
48
|
0
|
|
|
|
|
0
|
Carp::croak 'name?'; |
49
|
|
|
|
|
|
|
} |
50
|
13
|
50
|
|
|
|
53
|
if ( ref $sub ne 'CODE' ) { |
51
|
0
|
|
|
|
|
0
|
Carp::croak qq{name[$name] code?}; |
52
|
|
|
|
|
|
|
} |
53
|
13
|
50
|
|
|
|
34
|
if ( exists $self->{_rpcs}->{$name} ) { |
54
|
0
|
|
|
|
|
0
|
Carp::croak qq{$name already registered}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
13
|
|
100
|
|
|
35
|
$options ||= {}; |
58
|
13
|
50
|
|
|
|
25
|
if ( ref $options ne 'HASH' ) { |
59
|
0
|
|
|
|
|
0
|
Carp::croak 'options?'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
13
|
|
|
|
|
22
|
my %obj = ( method => $sub ); |
63
|
|
|
|
|
|
|
OPTION: |
64
|
13
|
|
|
|
|
19
|
foreach my $opt ( 'with_mojo_tx', 'with_svc_obj', 'with_self' ) { |
65
|
39
|
100
|
|
|
|
50
|
if ( !exists $options->{$opt} ) { |
66
|
32
|
|
|
|
|
39
|
next OPTION; |
67
|
|
|
|
|
|
|
} |
68
|
7
|
|
|
|
|
12
|
$obj{$opt} = $options->{$opt}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
13
|
|
|
|
|
24
|
$self->{_rpcs}->{$name} = \%obj; |
72
|
13
|
|
|
|
|
72
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |