| 1 | package JSON::RPC2::AnyEvent::Server::PSGI; | ||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use 5.008005; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use JSON::RPC2::AnyEvent::Constants qw(ERR_PARSE_ERROR); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use JSON::RPC2::AnyEvent::Server; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub JSON::RPC2::AnyEvent::Server::to_psgi_app { | ||||||||||||||||||||||||||||||
|
Subroutine
to_psgi_app: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 18 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 19 | 19 | ▶ | sub{ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||
| 20 | 19 | my $req = Plack::Request->new(shift); | |||||||||||||||||||||||||||||||
| 21 | 19 | ▶ | if ( $req->method eq 'GET' or $req->method eq 'HEAD' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$req->method eq "GET" or $req->method eq "HEAD"
MC/DC50%1/2
$req->method eq "GET" or $req->method eq "HEAD"
$req->method eq "GET"
$req->method eq "HEAD"
Truth table66%2/3
A or B
A= $req->method eq "GET"B= $req->method eq "HEAD"
| |||||||||||||||||||||||||||||||||
| 22 | 5 | return _dispatch_url_query($self, $req); | |||||||||||||||||||||||||||||||
| 23 | } elsif ( $req->method eq 'POST' ) { | ||||||||||||||||||||||||||||||||
| 24 | 14 | ▶ | return $req->content_type =~ m|^application/x-www-form-urlencoded$|i | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | ? _dispatch_url_query($self, $req) | ||||||||||||||||||||||||||||||||
| 26 | : _dispatch_json($self, $req); | ||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||
| 28 | 0 | return [405, ['Content-type' => 'text/plain'], ['Method Not Allowed']] | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | 4 | } | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 5 | my $json = JSON->new->utf8; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 11 | ▶ | sub _dispatch_url_query { | ||||||||||||||||||||||||||||||
|
Subroutine
_dispatch_url_query: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 36 | 11 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||
| 37 | 11 | _dispatch_aux($self, { | |||||||||||||||||||||||||||||||
| 38 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||
| 39 | id => undef, | ||||||||||||||||||||||||||||||||
| 40 | method => substr($req->path_info, 1), | ||||||||||||||||||||||||||||||||
| 41 | params => $req->parameters->mixed, | ||||||||||||||||||||||||||||||||
| 42 | }); | ||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | sub _dispatch_json { | ||||||||||||||||||||||||||||||
|
Subroutine
_dispatch_json: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||
| 46 | 8 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | try{ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 48 | 8 | my $hash = $json->decode($req->content); | |||||||||||||||||||||||||||||||
| 49 | 8 | _dispatch_aux($self, $hash); | |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 51 | 0 | [200, ['Content-Type', 'application/json'], [$json->encode({ | |||||||||||||||||||||||||||||||
| 52 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||
| 53 | id => undef, | ||||||||||||||||||||||||||||||||
| 54 | error => {code => ERR_PARSE_ERROR, message => 'Parse error', data => shift} | ||||||||||||||||||||||||||||||||
| 55 | })]] | ||||||||||||||||||||||||||||||||
| 56 | 8 | }; | |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 19 | ▶ | sub _dispatch_aux { | ||||||||||||||||||||||||||||||
|
Subroutine
_dispatch_aux: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 60 | 19 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||||||
| 61 | 19 | my $cv = $self->dispatch($hash); | |||||||||||||||||||||||||||||||
| 62 | 19 | ▶ | return [200, [], []] unless $cv; # notification | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 17 | ▶ | sub{ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 64 | 17 | my $writer = shift->([200, ['Content-Type', 'application/json']]); | |||||||||||||||||||||||||||||||
| 65 | 17 | ▶ | $cv->cb(sub{ | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 66 | 17 | my $res = shift->recv; | |||||||||||||||||||||||||||||||
| 67 | 17 | $writer->write($json->encode($res)); | |||||||||||||||||||||||||||||||
| 68 | 17 | $writer->close; | |||||||||||||||||||||||||||||||
| 69 | 17 | }); | |||||||||||||||||||||||||||||||
| 70 | 17 | }; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 5 | 1; | |||||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||||||