| 1 | package Catalyst::Plugin::Server::JSONRPC::Batch; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Class::Load (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use HTTP::Body (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our $Method = 'system.handle_batch'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.0
| |||||||||||||||||||||||||||||
| 16 | 1 | my $class = 'JSON::RPC::Common::Procedure::Call'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | Class::Load::load_class($class); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | my $meta = $class->meta; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | $meta->make_mutable(); | |||||||||||||||||||||||||||
| 23 | $meta->add_around_method_modifier( | ||||||||||||||||||||||||||||
| 24 | 'inflate', | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 26 | 0 | my ($meth, $class, @args) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (@args == 1 && ref($args[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@args == 1 and ref $args[0] eq "ARRAY"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1
ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 29 | 0 | return $class->new_from_data( | |||||||||||||||||||||||||||
| 30 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||
| 31 | id => scalar(time()), | ||||||||||||||||||||||||||||
| 32 | method => $Catalyst::Plugin::Server::JSONRPC::Batch::Method, | ||||||||||||||||||||||||||||
| 33 | params => $args[0] | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||
| 37 | 0 | return $meth->($class, @args); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||||||||||
| 41 | 1 | $meta->make_immutable(); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub setup_engine { | ||||||||||||||||||||||||||
|
Subroutine
setup_engine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $app = shift(); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $app->server->jsonrpc->add_private_method( | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $Method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($c, @args) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $config = $c->server->jsonrpc->config; | |||||||||||||||||||||||||||
| 53 | 0 | my $req = $c->req; | |||||||||||||||||||||||||||
| 54 | 0 | my $res = $c->res; | |||||||||||||||||||||||||||
| 55 | 0 | my $stash = $c->stash; | |||||||||||||||||||||||||||
| 56 | 0 | my $parser = $req->jsonrpc->_jsonrpc_parser; | |||||||||||||||||||||||||||
| 57 | 0 | my @results; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # HACK: Store values. | ||||||||||||||||||||||||||||
| 60 | 0 | my $body = $req->_body; | |||||||||||||||||||||||||||
| 61 | 0 | my $path = $config->path; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | foreach (map { $parser->encode($_) } @{$req->args}) { | |||||||||||||||||||||||||||
| 64 | 0 | $config->path(''); | |||||||||||||||||||||||||||
| 65 | 0 | $stash->{jsonrpc_generated} = 0; | |||||||||||||||||||||||||||
| 66 | 0 | $req->_body(HTTP::Body->new($req->content_type, length($_))); | |||||||||||||||||||||||||||
| 67 | 0 | $req->_body->add($_); | |||||||||||||||||||||||||||
| 68 | 0 | $res->body(''); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $c->prepare_action(); | |||||||||||||||||||||||||||
| 71 | 0 | $c->dispatch(); | |||||||||||||||||||||||||||
| 72 | $stash->{current_view_instance}->process($c) | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | unless $stash->{jsonrpc_generated}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | push(@results, $res->body); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Restore values. | ||||||||||||||||||||||||||||
| 79 | 0 | $req->_body($body); | |||||||||||||||||||||||||||
| 80 | 0 | $config->path($path); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $result = '[' . join(',', @results) . ']'; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | $res->content_length(length($result)); | |||||||||||||||||||||||||||
| 85 | 0 | $res->body($result); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | ); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $app->next::method(@_); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||