line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
package CGI::JSONRPC::Base; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
821
|
use JSON::Syck; |
|
1
|
|
|
|
|
3429
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
8
|
use JSON::Syck qw(Dump Load); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
244
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
(our $JAVASCRIPT = __FILE__) =~ s{\.pm$}{.js}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
0
|
54
|
my($class, %args) = @_; |
16
|
1
|
|
|
|
|
9
|
return bless { dispatcher => $class->default_dispatcher, %args }, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub default_dispatcher { |
20
|
1
|
|
|
1
|
0
|
7
|
'CGI::JSONRPC::Dispatcher' |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub run_json_request { |
25
|
0
|
|
|
0
|
0
|
0
|
my($self, $json) = @_; |
26
|
0
|
|
|
|
|
0
|
my $data = (JSON::Syck::Load($json))[0]; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
0
|
|
|
0
|
die "Did not get a hash from RPC request!" |
29
|
|
|
|
|
|
|
unless(ref($data) && ref($data) eq 'HASH'); |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
0
|
unless($data->{method}) { |
32
|
0
|
|
|
|
|
0
|
warn "JSONRPC payload did not have a method!"; |
33
|
0
|
|
|
|
|
0
|
return $self->return_error($data, "JSONRPC payload did not have a method!"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
return $self->run_data_request($data); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub data_request { |
40
|
3
|
|
|
3
|
0
|
5
|
my($self, $data) = @_; |
41
|
3
|
|
50
|
|
|
10
|
$data->{params} ||= []; |
42
|
3
|
|
|
|
|
17
|
my $method = "$self->{dispatcher}\::$data->{method}"; |
43
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
362
|
|
44
|
3
|
|
|
|
|
7
|
return(&{$method}($self, $data->{id}, @{$data->{params}})); |
|
3
|
|
|
|
|
45
|
|
|
3
|
|
|
|
|
5
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub run_data_request { |
48
|
3
|
|
|
3
|
0
|
95
|
my($self, $data) = @_; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
5
|
my @rv = eval { $self->data_request($data); }; |
|
3
|
|
|
|
|
17
|
|
51
|
|
|
|
|
|
|
|
52
|
3
|
100
|
|
|
|
39
|
if(my $error = $@) { |
53
|
2
|
|
|
|
|
13
|
warn $error; |
54
|
2
|
|
|
|
|
113
|
return $self->return_error($data, $error); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
|
|
5
|
if(defined $data->{id}) { |
58
|
1
|
|
|
|
|
9
|
return $self->return_result($data, \@rv); |
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
0
|
return ""; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub return_result { |
65
|
1
|
|
|
1
|
0
|
2
|
my($self, $data, $result) = @_; |
66
|
1
|
|
|
|
|
163
|
return JSON::Syck::Dump({ id => $data->{id}, result => $result }) |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub return_error { |
70
|
2
|
|
|
2
|
0
|
5
|
my($self, $data, $error) = @_; |
71
|
2
|
50
|
|
|
|
95
|
return JSON::Syck::Dump({ |
72
|
|
|
|
|
|
|
id => (defined $data->{id} ? $data->{id} : undef), |
73
|
|
|
|
|
|
|
error => $error |
74
|
|
|
|
|
|
|
}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub return_javascript { |
78
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
79
|
0
|
0
|
|
|
|
|
if(my $class = $self->{path_info}) { |
80
|
0
|
|
|
|
|
|
my $data = { |
81
|
|
|
|
|
|
|
params => [ $class ], method => "jsonrpc_javascript", id => 0 |
82
|
|
|
|
|
|
|
}; |
83
|
0
|
|
|
|
|
|
return $self->data_request($data); |
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
|
|
|
|
|
return $self->jsonrpc_javascript($self); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub jsonrpc_javascript { |
90
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my $fh; |
92
|
0
|
0
|
|
|
|
|
open($fh, '<', $JAVASCRIPT) or die $!; |
93
|
0
|
|
|
|
|
|
my @rv = <$fh>; |
94
|
0
|
0
|
|
|
|
|
if($self->{path}) { |
95
|
0
|
|
|
|
|
|
push(@rv, "\nJSONRPC.URL = '$self->{path}';\n"); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
return join('', @rv); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|