| 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
Condition100%3/3
ref $_rpcs eq "HASH" and exists $_rpcs->{$class}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $name or $name eq ""
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 ""
| |||||||||||||||||||||||||||||
| 48 | 0 | Carp::croak 'name?'; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 13 | ▶ | if ( ref $sub ne 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | Carp::croak qq{name[$name] code?}; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 13 | ▶ | if ( exists $self->{_rpcs}->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | Carp::croak qq{$name already registered}; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 13 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$options ||= {}
MC/DC100%1/1
$options ||= {}
$options
Truth table100%2/2
A
A= $options
| |||||||||||||||||||||||||||||
| 58 | 13 | ▶ | if ( ref $options ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||