| 1 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # JSONRPC version 1.1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use JSON (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use HTTP::Request (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use HTTP::Response (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | package JSON::RPC::Legacy::Server; | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $JSONRPC_Procedure_Able; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | if ($] >= 5.006) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | require JSON::RPC::Legacy::Procedure; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | $JSONRPC_Procedure_Able = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | $JSON::RPC::Legacy::Server::VERSION = '1.06'; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | for my $method (qw/request path_info json version error_message max_length charset content_type | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | error_response_header return_die_message/) | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | eval qq| | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
charset: not called CC=2 SCAR=16.0
Subroutine
content_type: not called CC=2 SCAR=16.0
Subroutine
error_message: not called CC=2 SCAR=16.0
Subroutine
error_response_header: not called CC=2 SCAR=16.0
Subroutine
json: called CC=2 SCAR=16.0
Subroutine
max_length: not called CC=2 SCAR=16.0
Subroutine
path_info: not called CC=2 SCAR=16.0
Subroutine
request: not called CC=2 SCAR=16.0
Subroutine
return_die_message: not called CC=2 SCAR=16.0
Subroutine
version: not called CC=2 SCAR=16.0
Pod
documented
Pod
documented
Pod
undocumented
Pod
undocumented
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub $method { | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | \$_[0]->{$method} = \$_[1] if defined \$_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | \$_[0]->{$method}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |; | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub create_json_coder { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_json_coder: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | JSON->new->utf8; # assumes UTF8 | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | bless { | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | max_length => 1024 * 100, | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | charset => 'UTF-8', | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | content_type => 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | json => $class->create_json_coder, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | loaded_module => { name => {}, order => [], }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | @_, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | *dispatch_to = *dispatch; # Alias | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub dispatch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (@arg == 0){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | Carp::carp "Run test mode..."; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | elsif (@arg > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | for my $pkg (@arg) { | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->_load_module($pkg); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (ref $arg[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | for my $pkg (@{$arg[0]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->_load_module($pkg); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | elsif (ref $arg[0] eq 'HASH') { # Lazy loading | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | for my $path (keys %{$arg[0]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $pkg = $arg[0]->{$path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->{dispatch_path}->{$path} = $pkg; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | elsif (ref $arg[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | Carp::croak 'Invalid dispatch value.'; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | else { # Single module | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->_load_module($arg[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub handle { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my ($obj, $res, $jsondata); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($self->request->method eq 'POST') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $jsondata = $self->retrieve_json_from_post(); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif ($self->request->method eq 'GET') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $jsondata = $self->retrieve_json_from_get(); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( $jsondata ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $obj = eval q| $self->json->decode($jsondata) |; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->raise_error(code => 201, message => "Can't parse JSON data."); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | else { # may have error_response_header at retroeve_json_from_post / get | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | unless ($self->error_response_header) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->error_response_header($self->response_header(403, 'No data.')); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($obj) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $res = $self->_handle($obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | unless ($self->error_response_header) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $self->response( $self->response_header(200, $res) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->response( $self->error_response_header ); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub retrieve_json_from_post { } # must be implemented in subclass | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieve_json_from_post: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub retrieve_json_from_get { } # must be implemented in subclass | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieve_json_from_get: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub response { } # must be implemented in subclass | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub raise_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raise_error: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ($self, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $status_code = $opt{status_code} || 200; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{'status_code'} || 200
MC/DC0%0/1
$opt{'status_code'} || 200
$opt{'status_code'}
Truth table0%0/2
A
A= $opt{'status_code'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (exists $opt{version} and $opt{version} ne '1.1') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opt{"version"} and $opt{"version"} ne "1.1"
MC/DC0%0/2
exists $opt{"version"} and $opt{"version"} ne "1.1"
exists $opt{"version"}
$opt{"version"} ne "1.1"
Truth table0%0/3
A and B
A= exists $opt{"version"}B= $opt{"version"} ne "1.1"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->version(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->version(1.1); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $res = $self->_error($opt{id}, $opt{code}, $opt{message}); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->error_response_header($self->response_header($status_code, $res)); | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub response_header { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $code, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $h = HTTP::Headers->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $h->header('Content-Type' => $self->content_type . '; charset=' . $self->charset); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | HTTP::Response->new($code => undef, $h, $result); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub _handle { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $obj->{version} ? $self->version(1.1) : $self->version(0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $method = $obj->{method}; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (!defined $method) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return $self->_error($obj->{id}, 300, "method is nothing."); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | elsif ($method =~ /[^-._a-zA-Z0-9]/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return $self->_error($obj->{id}, 301, "method is invalid."); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $procedure = $self->_find_procedure($method); | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | unless ($procedure) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return $self->_error($obj->{id}, 302, "No such a method : '$method'."); | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $params; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | unless ($obj->{version}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | unless ($obj->{params} and ref($obj->{params}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->{"params"} and ref $obj->{"params"} eq "ARRAY"
MC/DC0%0/2
$obj->{"params"} and ref $obj->{"params"} eq "ARRAY"
$obj->{"params"}
ref $obj->{"params"} eq "ARRAY"
Truth table0%0/3
A and B
A= $obj->{"params"}B= ref $obj->{"params"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return $self->_error($obj->{id}, 400, "Invalid params for JSONRPC 1.0."); | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unless ($params = $self->_argument_type_check($procedure->{argument_type}, $obj->{params})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return $self->_error($obj->{id}, 401, $self->error_message); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($obj->{version}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $result = ref $params ? eval q| $procedure->{code}->($self, $params) | | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | : eval q| $procedure->{code}->($self) | | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if(ref($params) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | @params = @$params; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $params[0] = $params; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $result = eval q| $procedure->{code}->($self, @params) |; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($self->error_response_header) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | elsif ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return $self->_error($obj->{id}, 500, ($self->return_die_message ? $@ : 'Procedure error.')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (!$obj->{version} and !defined $obj->{id}) { # notification | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj->{"version"} or defined $obj->{"id"}
MC/DC0%0/2
$obj->{"version"} or defined $obj->{"id"}
$obj->{"version"}
defined $obj->{"id"}
Truth table0%0/3
A or B
A= $obj->{"version"}B= defined $obj->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $return_obj = {result => $result}; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ($obj->{version}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $return_obj->{version} = '1.1'; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $return_obj->{error} = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $return_obj->{id} = $obj->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return $self->json->encode($return_obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub _find_procedure { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_procedure: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($self, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $found; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | my $classname; | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $system_call; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($method =~ /^system\.(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $system_call = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $method = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif ($method =~ /\./) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my @p = split/\./, $method; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $method = pop @p; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $classname= join('::', @p); | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ($self->{dispatch_path}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $path = $self->{path_info}; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (my $pkg = $self->{dispatch_path}->{$path}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | return if ( $classname and $pkg ne $classname ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$classname and $pkg ne $classname
MC/DC0%0/2
$classname and $pkg ne $classname
$classname
$pkg ne $classname
Truth table0%0/3
A and B
A= $classnameB= $pkg ne $classname
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return if ( $JSONRPC_Procedure_Able and JSON::RPC::Legacy::Procedure->can( $method ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$JSONRPC_Procedure_Able and "JSON::RPC::Legacy::Procedure"->can($method)
MC/DC0%0/2
$JSONRPC_Procedure_Able and "JSON::RPC::Legacy::Procedure"->can($method)
$JSONRPC_Procedure_Able
"JSON::RPC::Legacy::Procedure"->can($method)
Truth table0%0/3
A and B
A= $JSONRPC_Procedure_AbleB= "JSON::RPC::Legacy::Procedure"->can($method)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $self->_load_module($pkg); | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($system_call) { $pkg .= '::system' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return $self->_method_is_ebable($pkg, $method, $system_call); | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | for my $pkg (@{$self->{loaded_module}->{order}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | next if ( $classname and $pkg ne $classname ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$classname and $pkg ne $classname
MC/DC0%0/2
$classname and $pkg ne $classname
$classname
$pkg ne $classname
Truth table0%0/3
A and B
A= $classnameB= $pkg ne $classname
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | next if ( $JSONRPC_Procedure_Able and JSON::RPC::Legacy::Procedure->can( $method ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$JSONRPC_Procedure_Able and "JSON::RPC::Legacy::Procedure"->can($method)
MC/DC0%0/2
$JSONRPC_Procedure_Able and "JSON::RPC::Legacy::Procedure"->can($method)
$JSONRPC_Procedure_Able
"JSON::RPC::Legacy::Procedure"->can($method)
Truth table0%0/3
A and B
A= $JSONRPC_Procedure_AbleB= "JSON::RPC::Legacy::Procedure"->can($method)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ($system_call) { $pkg .= '::system' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ( my $ret = $self->_method_is_ebable($pkg, $method, $system_call) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | sub _method_is_ebable { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_method_is_ebable: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my ($self, $pkg, $method, $system_call) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $allowable_procedure = $pkg->can('allowable_procedure'); | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ( $allowable_procedure ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ( exists $allowable_procedure->()->{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $code = $allowable_procedure->()->{ $method }; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( $code or ( $code = $pkg->can($method) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$code or $code = $pkg->can($method)
MC/DC0%0/2
$code or $code = $pkg->can($method)
$code
$code = $pkg->can($method)
Truth table0%0/3
A or B
A= $codeB= $code = $pkg->can($method)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return {code => $code} if ($system_call or !$JSONRPC_Procedure_Able); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$system_call or not $JSONRPC_Procedure_Able
MC/DC0%0/2
$system_call or not $JSONRPC_Procedure_Able
$system_call
not $JSONRPC_Procedure_Able
Truth table0%0/3
A or not(B)
A= $system_callB= not $JSONRPC_Procedure_Able
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ( my $procedure = JSON::RPC::Legacy::Procedure::check($pkg, $code) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return if ($procedure->{return_type} and $procedure->{return_type} eq 'Private'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$procedure->{"return_type"} and $procedure->{"return_type"} eq "Private"
MC/DC0%0/2
$procedure->{"return_type"} and $procedure->{"return_type"} eq "Private"
$procedure->{"return_type"}
$procedure->{"return_type"} eq "Private"
Truth table0%0/3
A and B
A= $procedure->{"return_type"}B= $procedure->{"return_type"} eq "Private"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $procedure->{code} = $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return $procedure; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($system_call) { # if not found, default system.foobar | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ( my $code = 'JSON::RPC::Legacy::Server::system'->can($method) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return {code => $code}; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub _argument_type_check { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_argument_type_check: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my ($self, $type, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | unless (defined $type) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return defined $params ? $params : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $regulated; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if (ref $params eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if (@{$type->{position}} != @$params) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $self->error_message("Number of params is mismatch."); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if (my $hash = $type->{names}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | for my $name (keys %$hash) { | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $regulated->{$name} = $params->[$i++]; | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | elsif (ref $params eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if (@{$type->{position}} != keys %$params) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $self->error_message("Number of params is mismatch."); | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (my $hash = $type->{names}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | for my $name (keys %$params) { | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($name =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $realname = $type->{position}[$name]; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $regulated->{$realname} = $params->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $regulated->{$name} = $params->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif (!defined $params) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if (@{$type->{position}} != 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $self->error_message("Number of params is mismatch."); | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->error_message("the params member is any other type except JSON Object or Array."); | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | return $regulated ? $regulated : $params; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub _load_module { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_module: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my ($self, $pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | eval qq| require $pkg |; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | Carp::croak $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $self->{loaded_module}->{name}->{$pkg} = $pkg; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | push @{ $self->{loaded_module}->{order} }, $pkg; | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # Error Handling | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my ($self, $id, $code, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ($self->can('translate_error_message')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $message = $self->translate_error_message($code, $message); | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my $error_obj = { | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | name => 'JSONRPCError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if ($self->version) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $obj = { | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | version => "1.1", | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | error => $error_obj, | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | $obj->{id} = $id if (defined $id); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | return '' if (!defined $id); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $obj = { | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | result => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | error => $message, | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return $self->json->encode($obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | package JSON::RPC::Legacy::Server::system; | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub describe { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | sdversion => "1.0", | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | name => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | summary => 'Default system description', | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||