Lim/RPC/Server.pm

filter: Statementstmt 63.0% 203 / 322 Branchbran 34.3% 68 / 198 Conditioncond 24.4% 11 / 45 MC/DCmcdc 6.9% 2 / 29 Subroutinesub 96.1% 25 / 26 Podpod 100% 9 / 9 totaltotal 50.5% 318 / 629 SCAR 76.4
CC
125
Cov
50%
serve
1311.3
__ANON__
237.5
process_module_call_uri_map
20.0
CRAP 2088.5
« Lim/Util/DBI.pm ↑ Summary Lim/RPC/Client.pm »
1 package Lim::RPC::Server;
2  
3 10 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use URI::Split ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use Lim ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Lim::RPC ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Lim::RPC::Value ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use Lim::RPC::Value::Collection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Lim::RPC::Protocols ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Lim::RPC::Transports ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use Lim::RPC::URIMaps ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 =encoding utf8
21  
22 =head1 NAME
23  
24 ...
25  
26 =head1 VERSION
27  
28 See L<Lim> for version.
29  
30 =cut
31  
32 10 our $VERSION = $Lim::VERSION;
33  
34 =head1 SYNOPSIS
35  
36 ...
37  
38 =head1 SUBROUTINES/METHODS
39  
40 =head2 new
41  
42 =cut
43  
44 sub new {
45 4 ▶ my $this = shift;
Subroutine new: called CC=11 SCAR=26.7
Pod documented
46 4 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
47 4 my %args = ( @_ );
48 4 my $self = {
49 logger => Log::Log4perl->get_logger,
50 protocol => {},
51 transports => [],
52 module => {}
53 };
54 4 bless $self, $class;
55  
56 4 ▶ unless (defined $args{uri}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"uri"}) 0 4 4
57 0 confess __PACKAGE__, ': No uri specified';
58 }
59  
60 4 ▶ foreach my $uri (ref($args{uri}) eq 'ARRAY' ? @{$args{uri}} : $args{uri}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'uri'} eq 'ARRAY' ? : 0 4 4
61 4 my ($scheme, $auth, $path, $query, $frag) = URI::Split::uri_split($uri);
62  
63 4 ▶ if ($scheme =~ /^([a-z0-9_\-\.]+)(?:\+([a-z0-9_\-\.\+]+))*/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme =~ /^([a-z0-9_\-\.]+)(?:\+([a-z0-9_\-\.\+]+))*/ou) { } 4 0 4
64 4 my ($transport_name, $protocols) = ($1, $2);
65 4 my (@protocols, $transport);
66 4 $uri = URI->new('', 'http');
67 4 $uri->query($query);
68 4 $uri->host_port($auth);
69
70 4 foreach my $protocol_name (split(/\+/o, $protocols)) {
71 4 ▶ unless (exists $self->{protocol}->{$protocol_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'protocol'}{$protocol_name}) { } 0 4 4
72 4 my $protocol;
73  
74 4 ▶ unless (defined ($protocol = Lim::RPC::Protocols->instance->protocol($protocol_name, server => $self))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($protocol = "Lim::RPC::Protocols"->instance->protocol($protocol_name, "server", $self))) 0 4 4
75 0 confess __PACKAGE__, ': Protocol ', $protocol_name, ' does not exists';
76 }
77
78 4 $self->{protocol}->{$protocol_name} = $protocol;
79 4 push(@protocols, $protocol);
80 }
81 else {
82 0 push(@protocols, $self->{protocol}->{$protocol_name});
83 }
84 }
85
86 4 ▶ unless (defined ($transport = Lim::RPC::Transports->instance->transport($transport_name, server => $self, uri => $uri))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($transport = "Lim::RPC::Transports"->instance->transport($transport_name, "server", $self, "uri", $uri))) 0 4 4
87 0 confess __PACKAGE__, ': Transport ', $transport_name, ' does not exists';
88 }
89
90 4 $transport->add_protocol(@protocols);
91 4 push(@{$self->{transports}}, $transport);
92 }
93 else {
94 0 confess __PACKAGE__, ': Unable to parse URI schema: ', $uri;
95 }
96 }
97  
98 4 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('new ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("new ", __PACKAGE__, " ", $self) 4 0 4
99 4 $self;
100 }
101  
102 sub DESTROY {
103 4 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=2 SCAR=7.0
104 4 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('destroy ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("destroy ", __PACKAGE__, " ", $self) 4 0 4
105  
106 4 delete $self->{transports};
107 4 delete $self->{module};
108 4 delete $self->{protocol};
109 }
110  
111 =head2 serve
112  
113 =cut
114  
115 sub serve {
116 4 ▶ my ($self) = shift;
Subroutine serve: called CC=80 SCAR=71.8
Pod documented
117  
118 4 foreach my $module (@_) {
119 4 my $obj;
120  
121 4 eval {
122 4 $obj = $module->Server;
123 };
124 4 ▶ if (!defined $obj or $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $obj or $@) 0 4 4
Condition33%1/3
not defined $obj or $@
l!l&&r!l&&!r
004
MC/DC0%0/2
not defined $obj or $@
not defined $obj $@
Truth table33%1/3
not(A) or B
A= not defined $objB= $@
ABresult
1X1
011
000
125 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $module, (defined $@ ? ': '.$@ : ''));
Branch: 2 branches
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $module, defined $@ ? ': ' . $@ : "") 0 0 0
defined $@ ? : 0 0 0
126 0 next;
127 }
128  
129 4 ▶ if ($obj->isa('Lim::Component::Server')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Lim::Component::Server")) 4 0 4
130 4 my $name = lc($module->Name);
131
132 4 ▶ if (exists $self->{module}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"module"}{$name}) 0 4 4
133 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': plugin already served');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": plugin already served") 0 0 0
134 0 next;
135 }
136
137 4 ▶ unless ($module->VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module->VERSION) 0 4 4
138 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': no VERSION specified in plugin');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": no VERSION specified in plugin") 0 0 0
139 0 next;
140 }
141
142 4 my $calls = $module->Calls;
143 4 ▶ unless ($calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($calls) 0 4 4
144 0 ▶ Lim::INFO and $self->{logger}->info('Not serving ', $name, ', nothing to serve');
Branch: 1 branch
BranchTrueFalseTotal
Lim::INFO() and $self->{"logger"}->info("Not serving ", $name, ", nothing to serve") 0 0 0
145 0 next;
146 }
147 4 ▶ unless (ref($calls) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $calls eq "HASH") 0 4 4
148 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': Calls() return was invalid');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": Calls() return was invalid") 0 0 0
149 0 next;
150 }
151 4 ▶ unless (%$calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$calls) 0 4 4
152 0 ▶ Lim::INFO and $self->{logger}->info('Not serving ', $name, ', nothing to serve');
Branch: 1 branch
BranchTrueFalseTotal
Lim::INFO() and $self->{"logger"}->info("Not serving ", $name, ", nothing to serve") 0 0 0
153 0 next;
154 }
155
156 4 my $uri_maps = {};
157
158 4 foreach my $call (keys %$calls) {
159 20 ▶ unless ($obj->can($call)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->can($call)) 0 20 20
160 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': Missing specified call ', $call, ' function');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": Missing specified call ", $call, " function") 0 0 0
161 0 undef($calls);
162 0 last;
163 }
164  
165 20 my $create_call = 0;
166  
167 20 foreach my $protocol_name (keys %{$self->{protocol}}) {
168 20 my $base = 'Lim::RPC::ProtocolCall::'.$protocol_name.'::'.ref($obj);
169  
170 20 ▶ if ($base->isa('UNIVERSAL') and $base->can($call)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base->isa("UNIVERSAL") and $base->can($call)) 0 20 20
Condition33%1/3
$base->isa("UNIVERSAL") and $base->can($call)
!ll&&!rl&&r
0200
MC/DC0%0/2
$base->isa("UNIVERSAL") and $base->can($call)
$base->isa("UNIVERSAL") $base->can($call)
Truth table33%1/3
A and B
A= $base->isa("UNIVERSAL")B= $base->can($call)
ABresult
0X0
100
111
171 0 next;
172 }
173 20 $create_call = 1;
174 20 last;
175 }
176  
177 20 ▶ if ($create_call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($create_call) 20 0 20
178 20 my $call_def = $calls->{$call};
179
180 20 ▶ unless (ref($call_def) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $call_def eq "HASH") 0 20 20
181 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid definition") 0 0 0
182 0 undef($calls);
183 0 last;
184 }
185
186 20 ▶ if (exists $call_def->{uri_map}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $call_def->{"uri_map"}) 12 8 20
187 12 ▶ unless (ref($call_def->{uri_map}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $call_def->{"uri_map"} eq "ARRAY") 0 12 12
188 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid uri_map parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid uri_map parameter definition") 0 0 0
189 0 undef($calls);
190 0 last;
191 }
192
193 12 my $uri_map = Lim::RPC::URIMaps->new;
194
195 12 foreach my $map (@{$call_def->{uri_map}}) {
196 20 ▶ if (defined (my $redirect_call = $uri_map->add($map))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $redirect_call = $uri_map->add($map))) { } 20 0 20
197 20 ▶ if ($redirect_call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redirect_call) 8 12 20
198 8 ▶ unless (exists $calls->{$redirect_call}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $calls->{$redirect_call}) 0 8 8
199 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid uri_map: redirected to non-existing call ', $redirect_call);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid uri_map: redirected to non-existing call ", $redirect_call) 0 0 0
200 0 undef($calls);
201 0 last;
202 }
203 }
204 }
205 else {
206 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid uri_map: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid uri_map: ", $@) 0 0 0
207 0 undef($calls);
208 0 last;
209 }
210 }
211 12 ▶ unless (defined $calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $calls) 0 12 12
212 0 last;
213 }
214
215 12 $uri_maps->{$call} = $uri_map;
216 }
217
218 20 ▶ if (exists $call_def->{in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $call_def->{"in"}) 12 8 20
219 12 ▶ unless (ref($call_def->{in}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $call_def->{"in"} eq "HASH") 0 12 12
220 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid in parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid in parameter definition") 0 0 0
221 0 undef($calls);
222 0 last;
223 }
224
225 12 my @keys = keys %{$call_def->{in}};
226 12 ▶ unless (scalar @keys) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @keys) 0 12 12
227 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid in parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid in parameter definition") 0 0 0
228 0 undef($calls);
229 0 last;
230 }
231
232 12 my @values = ($call_def->{in});
233 12 ▶ while (defined $calls and (my $value = shift(@values))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $calls and my $value = shift @values) 24 12 36
Condition66%2/3
defined $calls and my $value = shift @values
!ll&&!rl&&r
01224
MC/DC50%1/2
defined $calls and my $value = shift @values
defined $calls my $value = shift @values
Truth table66%2/3
A and B
A= defined $callsB= my $value = shift @values
ABresult
0X0
100
111
234 24 foreach my $key (keys %$value) {
235 24 ▶ if (ref($value->{$key}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value->{$key} eq 'HASH') { } 12 12 24
elsif (builtin::blessed($value->{$key})) { } 0 12 12
236 12 ▶ if (exists $value->{$key}->{''}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value->{$key}{''}) { } 0 12 12
237 0 eval {
238 0 my $collection = Lim::RPC::Value::Collection->new($value->{$key}->{''});
239 0 delete $value->{$key}->{''};
240 0 $value->{$key} = $collection->set_children($value->{$key});
241 };
242 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
243 0 push(@values, $value->{$key}->children);
244 0 next;
245 }
246 0 ▶ Lim::WARN and $self->{logger}->warn('Unable to create Lim::RPC::Value::Collection: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Unable to create Lim::RPC::Value::Collection: ", $@) 0 0 0
247 }
248 else {
249 12 push(@values, $value->{$key});
250 12 next;
251 }
252 }
253 elsif (blessed $value->{$key}) {
254 0 ▶ if ($value->{$key}->isa('Lim::RPC::Value')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$key}->isa("Lim::RPC::Value")) 0 0 0
255 0 next;
256 }
257 0 ▶ if ($value->{$key}->isa('Lim::RPC::Value::Collection')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$key}->isa("Lim::RPC::Value::Collection")) 0 0 0
258 0 push(@values, $value->{$key}->children);
259 0 next;
260 }
261 }
262 else {
263 12 eval {
264 12 $value->{$key} = Lim::RPC::Value->new($value->{$key});
265 };
266 12 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 12 0 12
267 12 next;
268 }
269 0 ▶ Lim::WARN and $self->{logger}->warn('Unable to create Lim::RPC::Value: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Unable to create Lim::RPC::Value: ", $@) 0 0 0
270 }
271  
272 0 ▶ Lim::WARN and $self->{logger}->warn('Can not server ', $name, ': call ', $call, ' has invalid in parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not server ", $name, ": call ", $call, " has invalid in parameter definition") 0 0 0
273 0 undef($calls);
274 }
275 }
276
277 12 ▶ unless (defined $calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $calls) 0 12 12
278 0 last;
279 }
280 }
281
282 20 ▶ if (exists $call_def->{out}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $call_def->{"out"}) 20 0 20
283 20 ▶ unless (ref($call_def->{out}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $call_def->{"out"} eq "HASH") 0 20 20
284 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid out parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid out parameter definition") 0 0 0
285 0 undef($calls);
286 0 last;
287 }
288
289 20 my @keys = keys %{$call_def->{out}};
290 20 ▶ unless (scalar @keys) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @keys) 0 20 20
291 0 ▶ Lim::WARN and $self->{logger}->warn('Can not serve ', $name, ': call ', $call, ' has invalid out parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not serve ", $name, ": call ", $call, " has invalid out parameter definition") 0 0 0
292 0 undef($calls);
293 0 last;
294 }
295  
296 20 my @values = ($call_def->{out});
297 20 ▶ while (defined $calls and (my $value = shift(@values))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $calls and my $value = shift @values) 36 20 56
Condition66%2/3
defined $calls and my $value = shift @values
!ll&&!rl&&r
02036
MC/DC50%1/2
defined $calls and my $value = shift @values
defined $calls my $value = shift @values
Truth table66%2/3
A and B
A= defined $callsB= my $value = shift @values
ABresult
0X0
100
111
298 36 foreach my $key (keys %$value) {
299 76 ▶ if (ref($value->{$key}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value->{$key} eq 'HASH') { } 16 60 76
elsif (builtin::blessed($value->{$key})) { } 0 60 60
300 16 ▶ if (exists $value->{$key}->{''}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value->{$key}{''}) { } 0 16 16
301 0 eval {
302 0 my $collection = Lim::RPC::Value::Collection->new($value->{$key}->{''});
303 0 delete $value->{$key}->{''};
304 0 $value->{$key} = $collection->set_children($value->{$key});
305 };
306 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
307 0 push(@values, $value->{$key}->children);
308 0 next;
309 }
310 0 ▶ Lim::WARN and $self->{logger}->warn('Unable to create Lim::RPC::Value::Collection: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Unable to create Lim::RPC::Value::Collection: ", $@) 0 0 0
311 }
312 else {
313 16 push(@values, $value->{$key});
314 16 next;
315 }
316 }
317 elsif (blessed $value->{$key}) {
318 0 ▶ if ($value->{$key}->isa('Lim::RPC::Value')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$key}->isa("Lim::RPC::Value")) 0 0 0
319 0 next;
320 }
321 0 ▶ if ($value->{$key}->isa('Lim::RPC::Value::Collection')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{$key}->isa("Lim::RPC::Value::Collection")) 0 0 0
322 0 push(@values, $value->{$key}->children);
323 0 next;
324 }
325 }
326 else {
327 60 eval {
328 60 $value->{$key} = Lim::RPC::Value->new($value->{$key});
329 };
330 60 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 60 0 60
331 60 next;
332 }
333 0 ▶ Lim::WARN and $self->{logger}->warn('Unable to create Lim::RPC::Value: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Unable to create Lim::RPC::Value: ", $@) 0 0 0
334 }
335  
336 0 ▶ Lim::WARN and $self->{logger}->warn('Can not server ', $name, ': call ', $call, ' has invalid out parameter definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and $self->{"logger"}->warn("Can not server ", $name, ": call ", $call, " has invalid out parameter definition") 0 0 0
337 0 undef($calls);
338 }
339 }
340
341 20 ▶ unless (defined $calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $calls) 0 20 20
342 0 last;
343 }
344 }
345
346 20 my $logger = $self->{logger};
347 20 weaken($logger);
348  
349 20 foreach my $protocol_name (keys %{$self->{protocol}}) {
350 20 my $base = 'Lim::RPC::ProtocolCall::'.$protocol_name.'::'.ref($obj);
351 20 my $protocol_call = $base.'::'.$call;
352 20 my $protocol = $self->{protocol}->{$protocol_name};
353 20 weaken($protocol);
354 20 my $weak_obj = $obj;
355 20 weaken($weak_obj);
356 20 weaken($call_def);
357  
358 20 ▶ if ($base->isa('UNIVERSAL') and $base->can($call)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base->isa("UNIVERSAL") and $base->can($call)) 0 20 20
Condition33%1/3
$base->isa("UNIVERSAL") and $base->can($call)
!ll&&!rl&&r
0200
MC/DC0%0/2
$base->isa("UNIVERSAL") and $base->can($call)
$base->isa("UNIVERSAL") $base->can($call)
Truth table33%1/3
A and B
A= $base->isa("UNIVERSAL")B= $base->can($call)
ABresult
0X0
100
111
359 0 next;
360 }
361
362 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
363 *$protocol_call = sub {
364 4 ▶ unless (defined $protocol and defined $weak_obj and defined $call_def) {
Subroutine __ANON__: called CC=25 SCAR=54.7
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $protocol and defined $weak_obj and defined $call_def) 0 4 4
Condition33%2/6
defined $protocol and defined $weak_obj and defined $call_def
!ll&&!rl&&r
004
defined $protocol and defined $weak_obj
!ll&&!rl&&r
004
MC/DC0%0/3
defined $protocol and defined $weak_obj and defined $call_def
defined $protocol defined $weak_obj defined $call_def
Truth table25%1/4
A and B and C
A= defined $protocolB= defined $weak_objC= defined $call_def
ABCresult
0XX0
10X0
1100
1111
365 0 return;
366 }
367 4 my ($self, $cb, $q, @args);
368 4 eval {
369 4 ($self, $cb, $q, @args) = $protocol->precall($call, @_);
370 };
371 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
372 0 ▶ Lim::WARN and defined $logger and $logger->warn($weak_obj, '->', $call, '() precall failed: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and defined $logger and $logger->warn($weak_obj, "->", $call, "() precall failed: ", $@) 0 0 0
Condition0%0/3
Lim::WARN() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::WARN() and defined $logger
Lim::WARN() defined $logger
Truth table0%0/3
A and B
A= Lim::WARN()B= defined $logger
ABresult
0X0
100
111
373 0 $weak_obj->Error($cb);
374 0 return;
375 }
376
377 4 ▶ Lim::RPC_DEBUG and defined $logger and $logger->debug('Call to ', $weak_obj, ' ', $call);
Branch: 1 branch
BranchTrueFalseTotal
Lim::RPC_DEBUG() and defined $logger and $logger->debug("Call to ", $weak_obj, " ", $call) 4 0 4
Condition33%1/3
Lim::RPC_DEBUG() and defined $logger
!ll&&!rl&&r
004
MC/DC0%0/2
Lim::RPC_DEBUG() and defined $logger
Lim::RPC_DEBUG() defined $logger
Truth table33%1/3
A and B
A= Lim::RPC_DEBUG()B= defined $logger
ABresult
0X0
100
111
378  
379 4 ▶ if (!defined $q) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $q) 4 0 4
380 4 $q = {};
381 }
382 4 ▶ if (ref($q) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $q ne "HASH") 0 4 4
383 0 ▶ Lim::WARN and defined $logger and $logger->warn($weak_obj, '->', $call, '() called without data as hash');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and defined $logger and $logger->warn($weak_obj, "->", $call, "() called without data as hash") 0 0 0
Condition0%0/3
Lim::WARN() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::WARN() and defined $logger
Lim::WARN() defined $logger
Truth table0%0/3
A and B
A= Lim::WARN()B= defined $logger
ABresult
0X0
100
111
384 0 $weak_obj->Error($cb);
385 0 return;
386 }
387
388 4 ▶ if (exists $call_def->{in}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $call_def->{'in'}) { } 0 4 4
elsif (%$q) { } 0 4 4
389 0 eval {
390 0 Lim::RPC::V($q, $call_def->{in});
391 };
392 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
393 0 ▶ Lim::WARN and defined $logger and $logger->warn($weak_obj, '->', $call, '() data validation failed: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and defined $logger and $logger->warn($weak_obj, "->", $call, "() data validation failed: ", $@) 0 0 0
Condition0%0/3
Lim::WARN() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::WARN() and defined $logger
Lim::WARN() defined $logger
Truth table0%0/3
A and B
A= Lim::WARN()B= defined $logger
ABresult
0X0
100
111
394 0 ▶ Lim::DEBUG and defined $logger and eval {
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and defined $logger and eval { do { $logger->debug(Dumper($q)); $logger->debug(Dumper($call_def->{"in"})) } } 0 0 0
Condition0%0/3
Lim::DEBUG() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::DEBUG() and defined $logger
Lim::DEBUG() defined $logger
Truth table0%0/3
A and B
A= Lim::DEBUG()B= defined $logger
ABresult
0X0
100
111
395 10 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
396 0 $logger->debug(Dumper($q));
397 0 $logger->debug(Dumper($call_def->{in}));
398 };
399 0 $weak_obj->Error($cb);
400 0 return;
401 }
402 }
403 elsif (%$q) {
404 0 ▶ Lim::WARN and defined $logger and $logger->warn($weak_obj, '->', $call, '() have data but no definition');
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and defined $logger and $logger->warn($weak_obj, "->", $call, "() have data but no definition") 0 0 0
Condition0%0/3
Lim::WARN() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::WARN() and defined $logger
Lim::WARN() defined $logger
Truth table0%0/3
A and B
A= Lim::WARN()B= defined $logger
ABresult
0X0
100
111
405 0 $weak_obj->Error($cb);
406 0 return;
407 }
408 4 $cb->set_call_def($call_def);
409
410 4 eval {
411 4 $weak_obj->$call($cb, $q, @args);
412 };
413 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
414 0 ▶ Lim::WARN and defined $logger and $logger->warn($weak_obj, '->', $call, '() failed: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::WARN() and defined $logger and $logger->warn($weak_obj, "->", $call, "() failed: ", $@) 0 0 0
Condition0%0/3
Lim::WARN() and defined $logger
!ll&&!rl&&r
000
MC/DC0%0/2
Lim::WARN() and defined $logger
Lim::WARN() defined $logger
Truth table0%0/3
A and B
A= Lim::WARN()B= defined $logger
ABresult
0X0
100
111
415 0 $weak_obj->Error($cb);
416 }
417 4 return;
418 20 };
419 }
420 }
421 }
422 4 ▶ unless ($calls) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($calls) 0 4 4
423 0 next;
424 }
425  
426 4 ▶ Lim::DEBUG and $self->{logger}->debug('serving ', $name);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("serving ", $name) 4 0 4
427
428 4 $self->{module}->{$name} = {
429 name => $name,
430 module => $module,
431 obj => $obj,
432 calls => $calls,
433 uri_maps => $uri_maps
434 };
435  
436 4 foreach my $protocol (values %{$self->{protocol}}) {
437 4 $protocol->serve($module, $name);
438 }
439 }
440 }
441
442 4 $self;
443 }
444  
445 =head2 have_module
446  
447 =cut
448  
449 sub have_module {
450 4 ▶ my ($self, $module) = @_;
Subroutine have_module: called CC=2 SCAR=7.6
Pod documented
451
452 4 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 4 4
453 0 return;
454 }
455
456 4 return 1;
457 }
458  
459 =head2 have_module_call
460  
461 =cut
462  
463 sub have_module_call {
464 2 ▶ my ($self, $module, $call) = @_;
Subroutine have_module_call: called CC=3 SCAR=12.7
Pod documented
465  
466 2 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 2 2
467 0 return;
468 }
469  
470 2 ▶ unless (exists $self->{module}->{$module}->{calls}->{$call}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}{"calls"}{$call}) 0 2 2
471 0 return;
472 }
473
474 2 return 1;
475 }
476  
477 =head2 module_obj
478  
479 =cut
480  
481 sub module_obj {
482 2 ▶ my ($self, $module) = @_;
Subroutine module_obj: called CC=2 SCAR=7.6
Pod documented
483  
484 2 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 2 2
485 0 return;
486 }
487  
488 2 return $self->{module}->{$module}->{obj};
489 }
490  
491 =head2 module_class
492  
493 =cut
494  
495 sub module_class {
496 6 ▶ my ($self, $module) = @_;
Subroutine module_class: called CC=2 SCAR=7.6
Pod documented
497  
498 6 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 6 6
499 0 return;
500 }
501  
502 6 return $self->{module}->{$module}->{module};
503 }
504  
505 =head2 module_obj_by_protocol
506  
507 =cut
508  
509 sub module_obj_by_protocol {
510 6 ▶ my ($self, $module, $protocol) = @_;
Subroutine module_obj_by_protocol: called CC=3 SCAR=12.7
Pod documented
511
512 6 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 6 6
513 0 return;
514 }
515  
516 6 ▶ unless (exists $self->{protocol}->{$protocol}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"protocol"}{$protocol}) 0 6 6
517 0 return;
518 }
519
520 6 bless {}, 'Lim::RPC::ProtocolCall::'.$protocol.'::'.$self->{module}->{$module}->{module}.'::Server';
521 }
522  
523 =head2 process_module_call_uri_map
524  
525 =cut
526  
527 sub process_module_call_uri_map {
528 0 ▶ my ($self, $module, $call, $uri, $data) = @_;
Subroutine process_module_call_uri_map: not called CC=4 SCAR=30.0
Pod documented
529  
530 0 ▶ unless (exists $self->{module}->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}) 0 0 0
531 0 return;
532 }
533
534 0 ▶ unless (ref($data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 0 0
535 0 return;
536 }
537  
538 0 ▶ unless (exists $self->{module}->{$module}->{uri_maps}->{$call}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"module"}{$module}{"uri_maps"}{$call}) 0 0 0
539 0 return;
540 }
541  
542 0 return $self->{module}->{$module}->{uri_maps}->{$call}->process($uri, $data);
543 }
544  
545 =head2 transports
546  
547 =cut
548  
549 sub transports {
550 4 ▶ @{$_[0]->{transports}};
Subroutine transports: called CC=1 SCAR=0.0
Pod documented
551 }
552  
553 =head1 AUTHOR
554  
555 Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >>
556  
557 =head1 BUGS
558  
559 Please report any bugs or feature requests to L<https://github.com/jelu/lim/issues>.
560  
561 =head1 SUPPORT
562  
563 You can find documentation for this module with the perldoc command.
564  
565 perldoc Lim
566  
567 You can also look for information at:
568  
569 =over 4
570  
571 =item * Lim issue tracker (report bugs here)
572  
573 L<https://github.com/jelu/lim/issues>
574  
575 =back
576  
577 =head1 ACKNOWLEDGEMENTS
578  
579 =head1 LICENSE AND COPYRIGHT
580  
581 Copyright 2012-2013 Jerry Lundström.
582  
583 This program is free software; you can redistribute it and/or modify it
584 under the terms of either: the GNU General Public License as published
585 by the Free Software Foundation; or the Artistic License.
586  
587 See http://dev.perl.org/licenses/ for more information.
588  
589  
590 =cut
591  
592 10 1; # End of Lim::RPC::Server
« Lim/Util/DBI.pm ↑ Summary Lim/RPC/Client.pm »