lib/MojoX/JSON/RPC/Service.pm

filter: Statementstmt 84.6% 33 / 39 Branchbran 62.5% 10 / 16 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 4 / 4 Podpod 100% 3 / 3 totaltotal 78.6% 59 / 75 CC 14 SCAR 20.2
CC
14
Cov
78%
register
11.3
register_rpc_method_names
4.4
new
3.0
CRAP 7.6
« lib/MojoX/JSON/RPC/Client.pm ↑ Summary lib/Mojolicious/Plugin/JsonRpcDispatcher.pm »
1 package MojoX::JSON::RPC::Service;
2  
3 3 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 {
6  
7 # Store rpc methods registered by register_rpc_method_names
8 3 my $_rpcs = undef;
9  
10 4 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
11 4 my $class = shift;
12 4 my $self = $class->SUPER::new(@_);
13  
14 # make shallow copy of class level rpcs
15 4 ▶ if ( ref $_rpcs eq 'HASH' && exists $_rpcs->{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_rpcs eq "HASH" and exists $_rpcs->{$class}) 1 3 4
Condition100%3/3
ref $_rpcs eq "HASH" and exists $_rpcs->{$class}
!ll&&!rl&&r
211
MC/DC100%2/2
ref $_rpcs eq "HASH" and exists $_rpcs->{$class}
ref $_rpcs eq "HASH" exists $_rpcs->{$class}
Truth table100%3/3
A and B
A= ref $_rpcs eq "HASH"B= exists $_rpcs->{$class}
ABresult
0X0
100
111
16 1 $self->{_rpcs} = { %{ $_rpcs->{$class} } };
17 }
18 4 return $self;
19 }
20  
21 1 ▶ sub register_rpc_method_names {
Subroutine register_rpc_method_names: called CC=4 SCAR=14.8
Pod documented
22 1 my ( $class, @methods ) = @_;
23  
24 METHOD:
25 1 foreach my $m (@methods) {
26 8 my $name = $class . '::' . $m;
27 8 my $method = eval qq|*{*$name}{CODE}|;
28  
29 8 ▶ if ( ref $method ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $method ne "CODE") 0 8 8
30 0 Carp::croak
31 qq{register_rpc_method_names: $name not a method.};
32 }
33 8 ▶ if ( exists $_rpcs->{$class}->{$m} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_rpcs->{$class}{$m}) 0 8 8
34 0 Carp::croak
35 qq{register_rpc_method_names: $name already registered.};
36 }
37 8 $_rpcs->{$class}->{$m} = { method => $method, with_svc_obj => 1 };
38 }
39  
40 1 return $class;
41 }
42 }
43  
44 3 ▶sub register {
Subroutine register: called CC=9 SCAR=24.2
Pod documented
45 13 my ( $self, $name, $sub, $options ) = @_;
46  
47 13 ▶ if ( !defined $name || $name eq q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $name eq "") 0 13 13
Condition33%1/3
not defined $name or $name eq ""
l!l&&r!l&&!r
0013
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name $name eq ""
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq ""
ABresult
1X1
011
000
48 0 Carp::croak 'name?';
49 }
50 13 ▶ if ( ref $sub ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub ne "CODE") 0 13 13
51 0 Carp::croak qq{name[$name] code?};
52 }
53 13 ▶ if ( exists $self->{_rpcs}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_rpcs"}{$name}) 0 13 13
54 0 Carp::croak qq{$name already registered};
55 }
56  
57 13 ▶ $options ||= {};
Condition100%2/2
$options ||= {}
l!l
49
MC/DC100%1/1
$options ||= {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
58 13 ▶ if ( ref $options ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options ne "HASH") 0 13 13
59 0 Carp::croak 'options?';
60 }
61  
62 13 my %obj = ( method => $sub );
63 OPTION:
64 13 foreach my $opt ( 'with_mojo_tx', 'with_svc_obj', 'with_self' ) {
65 39 ▶ if ( !exists $options->{$opt} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options->{$opt}) 32 7 39
66 32 next OPTION;
67 }
68 7 $obj{$opt} = $options->{$opt};
69 }
70  
71 13 $self->{_rpcs}->{$name} = \%obj;
72 13 return $self;
73 }
74  
75 3 1;
76  
77 __END__
« lib/MojoX/JSON/RPC/Client.pm ↑ Summary lib/Mojolicious/Plugin/JsonRpcDispatcher.pm »