Common/Marshal/Text.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 50.0% 4 / 8 totaltotal 89.4% 68 / 76 CC 3 SCAR 3.8
CC
3
Cov
92%
message_to_json
3.8
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Common/Procedure/Call.pm ↑ Summary Common/Procedure/Return/Version_2_0/Error.pm »
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
BranchTrueFalseTotal
if ($message->isa('JSON::RPC::Common::Procedure::Call')) { } 0 1 1
elsif ($message->isa('JSON::RPC::Common::Procedure::Return')) { } 1 0 1
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__
« Common/Procedure/Call.pm ↑ Summary Common/Procedure/Return/Version_2_0/Error.pm »