« Common/Procedure/Return/Version_1_0/Error.pm
↑ Summary
Common/Procedure/Return/Version_1_1/Error.pm »
| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package JSON::RPC::Common::Message; | ||||||||||||||||||||||||||||
| 4 | 6 | $JSON::RPC::Common::Message::VERSION = '0.11'; | |||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: JSON-RPC message role | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Class::Load qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use namespace::clean -except => [qw(meta)]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 6 | requires 'deflate'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 60 | ▶ | sub inflate { | ||||||||||||||||||||||||||
|
Subroutine
inflate: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 60 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 60 | my $data; | |||||||||||||||||||||||||||
| 19 | 60 | ▶ | if (@args == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 60 | ▶ | if (defined $args[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 6 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 60 | ▶ | (ref($args[0]) eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | || confess "Single parameters to inflate() must be a HASH ref"; | ||||||||||||||||||||||||||||
| 24 | 60 | $data = $args[0]; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 0 | $data = { @args }; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 60 | my $subclass = $class->_version_class( $class->_get_version($data), $data ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 60 | Class::Load::load_class($subclass); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 60 | $subclass->new_from_data(%$data); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 60 | ▶ | sub new_from_data { shift->new(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_from_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 60 | ▶ | sub _get_version { | ||||||||||||||||||||||||||
|
Subroutine
_get_version: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 41 | 60 | my ( $class, $data ) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 60 | ▶ | if ( exists $data->{jsonrpc} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 12 | return $data->{jsonrpc}; # presumably 2.0 | |||||||||||||||||||||||||||
| 45 | } elsif ( exists $data->{version} ) { | ||||||||||||||||||||||||||||
| 46 | 41 | return $data->{version}; # presumably 1.1 | |||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | 7 | return "1.0"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 60 | ▶ | sub _version_class { | ||||||||||||||||||||||||||
|
Subroutine
_version_class: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||
| 53 | 60 | my ( $class, $version, $data ) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 60 | my @numbers = ( $version =~ /(\d+)/g ) ; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 60 | ▶ | if ( $class eq __PACKAGE__ and $data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class eq __PACKAGE__ and $data
MC/DC50%1/2
$class eq __PACKAGE__ and $data
$class eq __PACKAGE__
$data
Truth table66%2/3
A and B
A= $class eq __PACKAGE__B= $data
| |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ( exists $data->{method} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | 2 | $class = "JSON::RPC::Common::Procedure::Call"; | |||||||||||||||||||||||||||
| 60 | ▶ | } elsif ( exists $data->{id} or exists $data->{result} ) { | |||||||||||||||||||||||||||
|
Condition33%1/3
exists $data->{"id"} or exists $data->{"result"}
MC/DC0%0/2
exists $data->{"id"} or exists $data->{"result"}
exists $data->{"id"}
exists $data->{"result"}
Truth table33%1/3
A or B
A= exists $data->{"id"}B= exists $data->{"result"}
| |||||||||||||||||||||||||||||
| 61 | 1 | $class = "JSON::RPC::Common::Procedure::Return"; | |||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||
| 63 | 0 | croak "Couldn't determine type of message (call or return)"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 60 | return join( "::", $class, join("_", Version => @numbers) ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 6 | __PACKAGE__ | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||