| 1 | #!/usr/bin/perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package JSON::RPC::Common::Marshal::Text; | ||||||||||||||
| 4 | 2 | $JSON::RPC::Common::Marshal::Text::VERSION = '0.11'; | |||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | # ABSTRACT: JSON text marshalling for L<JSON::RPC::Common>. | ||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use Carp qw(croak); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | use JSON (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 2 | ▶ | use JSON::RPC::Common::Message; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 2 | ▶ | use JSON::RPC::Common::Procedure::Call; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 2 | ▶ | use JSON::RPC::Common::Procedure::Return; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 2 | ▶ | use namespace::clean -except => [qw(meta)]; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 2 | has json => ( | |||||||||||||
| 18 | isa => "Object", | ||||||||||||||
| 19 | is => "rw", | ||||||||||||||
| 20 | handles => [qw(encode decode)], | ||||||||||||||
| 21 | lazy_build => 1, | ||||||||||||||
| 22 | ); | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | ▶ | sub _build_json { | ||||||||||||
|
Subroutine
_build_json: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | 1 | JSON->new; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 2 | has message_class => ( | |||||||||||||
| 29 | isa => "ClassName", | ||||||||||||||
| 30 | is => "rw", | ||||||||||||||
| 31 | default => "JSON::RPC::Common::Message", | ||||||||||||||
| 32 | handles => { "inflate_message" => "inflate" }, | ||||||||||||||
| 33 | ); | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 2 | has call_class => ( | |||||||||||||
| 36 | isa => "ClassName", | ||||||||||||||
| 37 | is => "rw", | ||||||||||||||
| 38 | default => "JSON::RPC::Common::Procedure::Call", | ||||||||||||||
| 39 | handles => { "inflate_call" => "inflate" }, | ||||||||||||||
| 40 | ); | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 2 | has return_class => ( | |||||||||||||
| 43 | isa => "ClassName", | ||||||||||||||
| 44 | is => "rw", | ||||||||||||||
| 45 | default => "JSON::RPC::Common::Procedure::Return", | ||||||||||||||
| 46 | handles => { "inflate_return" => "inflate" }, | ||||||||||||||
| 47 | ); | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 30 | ▶ | sub deflate_call { | ||||||||||||
|
Subroutine
deflate_call: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 50 | 30 | my ( $self, $call ) = @_; | |||||||||||||
| 51 | 30 | $call->deflate; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 1 | ▶ | sub deflate_return { | ||||||||||||
|
Subroutine
deflate_return: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 55 | 1 | my ( $self, $return ) = @_; | |||||||||||||
| 56 | 1 | $return->deflate; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | ▶ | sub message_to_json { | ||||||||||||
|
Subroutine
message_to_json: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||
| 60 | 1 | my ( $self, $message ) = @_; | |||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | ▶ | if ( $message->isa("JSON::RPC::Common::Procedure::Call") ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 63 | 0 | $self->call_to_json($message); | |||||||||||||
| 64 | } elsif ( $message->isa("JSON::RPC::Common::Procedure::Return") ) { | ||||||||||||||
| 65 | 1 | $self->return_to_json($message); | |||||||||||||
| 66 | } else { | ||||||||||||||
| 67 | 0 | croak "I dunno wtf $message is"; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 1 | ▶ | sub json_to_message { | ||||||||||||
|
Subroutine
json_to_message: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 72 | 1 | my ( $self, $json ) = @_; | |||||||||||||
| 73 | 1 | $self->inflate_message( $self->decode($json) ); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 14 | ▶ | sub call_to_json { | ||||||||||||
|
Subroutine
call_to_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 77 | 14 | my ( $self, $call ) = @_; | |||||||||||||
| 78 | 14 | $self->encode( $self->deflate_call($call) ); | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 1 | ▶ | sub return_to_json { | ||||||||||||
|
Subroutine
return_to_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 82 | 1 | my ( $self, $ret ) = @_; | |||||||||||||
| 83 | 1 | $self->encode( $self->deflate_return($ret) ); | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 21 | ▶ | sub json_to_call { | ||||||||||||
|
Subroutine
json_to_call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 87 | 21 | my ( $self, $json ) = @_; | |||||||||||||
| 88 | 21 | $self->inflate_call( $self->decode($json) ); | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 5 | ▶ | sub json_to_return { | ||||||||||||
|
Subroutine
json_to_return: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 92 | 5 | my ( $self, $json ) = @_; | |||||||||||||
| 93 | 5 | $self->inflate_return( $self->decode($json) ); | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||||||
| 97 | |||||||||||||||
| 98 | 2 | __PACKAGE__ | |||||||||||||
| 99 | |||||||||||||||
| 100 | __END__ | ||||||||||||||