Lim/RPC/Callback.pm

filter: Statementstmt 91.6% 33 / 36 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 91.6% 11 / 12 Podpod 100% 7 / 7 totaltotal 73.7% 59 / 80 SCAR 23.4
CC
9
Cov
75%
new
9.7
DESTROY
2.0
set_call_def
2.0
CRAP 10.3
« Lim/RPC/Transport.pm ↑ Summary Lim/Agent/CLI.pm »
1 package Lim::RPC::Callback;
2  
3 5 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Lim ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =encoding utf8
11  
12 =head1 NAME
13  
14 Lim::RPC::Callback - Base class of all RPC callbacks
15  
16 =head1 VERSION
17  
18 See L<Lim> for version.
19  
20 =cut
21  
22 =head1 SYNOPSIS
23  
24 =over 4
25  
26 package Lim::RPC::Callback::MyCallback;
27  
28 use base qw(Lim::RPC::Callback);
29  
30 =back
31  
32 =head1 METHODS
33  
34 =over 4
35  
36 =item $callback = Lim::RPC::Callback::MyCallback->new(key => value...)
37  
38 Create a new callback object.
39  
40 =over 4
41  
42 =item cb => $callback (required)
43  
44 Set the callback function related to this callback. This is set by
45 L<Lim::RPC::Server> depending on what protocol in incoming.
46  
47 =item client => $client (required)
48  
49 Set the L<Lim::RPC::Server::Client> related to this callback. This is set by
50 L<Lim::RPC::Server> on incoming calls.
51  
52 =back
53  
54 =cut
55  
56 sub new {
57 8 ▶ my $this = shift;
Subroutine new: called CC=7 SCAR=22.7
Pod documented
58 8 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
59 8 my %args = ( @_ );
60 8 my $self = {
61 logger => Log::Log4perl->get_logger
62 };
63 8 bless $self, $class;
64  
65 8 ▶ unless (defined $args{cb} and ref($args{cb}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"cb"} and ref $args{"cb"} eq "CODE") 0 8 8
Condition33%1/3
defined $args{"cb"} and ref $args{"cb"} eq "CODE"
!ll&&!rl&&r
008
MC/DC0%0/2
defined $args{"cb"} and ref $args{"cb"} eq "CODE"
defined $args{"cb"} ref $args{"cb"} eq "CODE"
Truth table33%1/3
A and B
A= defined $args{"cb"}B= ref $args{"cb"} eq "CODE"
ABresult
0X0
100
111
66 0 confess __PACKAGE__, ': cb not given or invalid';
67 }
68 8 ▶ unless (defined $args{reset_timeout} and ref($args{reset_timeout}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"reset_timeout"} and ref $args{"reset_timeout"} eq "CODE") 0 8 8
Condition33%1/3
defined $args{"reset_timeout"} and ref $args{"reset_timeout"} eq "CODE"
!ll&&!rl&&r
008
MC/DC0%0/2
defined $args{"reset_timeout"} and ref $args{"reset_timeout"} eq "CODE"
defined $args{"reset_timeout"} ref $args{"reset_timeout"} eq "CODE"
Truth table33%1/3
A and B
A= defined $args{"reset_timeout"}B= ref $args{"reset_timeout"} eq "CODE"
ABresult
0X0
100
111
69 0 confess __PACKAGE__, ': reset_timeout not given or invalid';
70 }
71
72 8 $self->{cb} = $args{cb};
73 8 $self->{reset_timeout} = $args{reset_timeout};
74  
75 8 $self->Init(@_);
76  
77 8 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('new ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("new ", __PACKAGE__, " ", $self) 8 0 8
78 8 $self;
79 }
80  
81 sub DESTROY {
82 8 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=2 SCAR=7.1
83
84 8 $self->Destroy;
85
86 8 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('destroy ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("destroy ", __PACKAGE__, " ", $self) 8 0 8
87 }
88  
89 =item $callback->Init(...)
90  
91 Called from C<new> on object creation with the same arguments as passed to
92 C<new>.
93  
94 Should be overloaded if you wish to do initial things on creation.
95  
96 =cut
97  
98 ▶sub Init {
Subroutine Init: called CC=1 SCAR=0.0
Pod documented
99 }
100  
101 =item $callback->Destroy(...)
102  
103 Called from C<DESTROY> on object destruction.
104  
105 Should be overloaded if you wish to do things on destruction.
106  
107 =cut
108  
109 ▶sub Destroy {
Subroutine Destroy: called CC=1 SCAR=0.0
Pod documented
110 }
111  
112 =item $callback->cb
113  
114 Return the callback.
115  
116 =cut
117  
118 sub cb {
119 10 ▶ $_[0]->{cb};
Subroutine cb: called CC=1 SCAR=0.0
Pod documented
120 }
121  
122 =item $callback->call_def
123  
124 Return the call definition set by C<set_call_def>.
125  
126 =cut
127  
128 sub call_def {
129 12 ▶ $_[0]->{call_def};
Subroutine call_def: called CC=1 SCAR=0.0
Pod documented
130 }
131  
132 =item $callback->set_call_def
133  
134 Set the call definition related to this callback. Returns the references to it
135 self.
136  
137 =cut
138  
139 sub set_call_def {
140 4 ▶ if (ref($_[1]) eq 'HASH') {
Subroutine set_call_def: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[1] eq "HASH") 4 0 4
141 4 $_[0]->{call_def} = $_[1];
142 }
143
144 4 $_[0];
145 }
146  
147 =item $callback->reset_timeout
148  
149 Reset the timeout of the client related to this callback.
150  
151 =cut
152  
153 sub reset_timeout {
154 0 ▶ $_[0]->{reset_timeout}->();
Subroutine reset_timeout: not called CC=1 SCAR=6.9
Pod documented
155 }
156  
157 =back
158  
159 =head1 AUTHOR
160  
161 Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >>
162  
163 =head1 BUGS
164  
165 Please report any bugs or feature requests to L<https://github.com/jelu/lim/issues>.
166  
167 =head1 SUPPORT
168  
169 You can find documentation for this module with the perldoc command.
170  
171 perldoc Lim::RPC::Callback
172  
173 You can also look for information at:
174  
175 =over 4
176  
177 =item * Lim issue tracker (report bugs here)
178  
179 L<https://github.com/jelu/lim/issues>
180  
181 =back
182  
183 =head1 ACKNOWLEDGEMENTS
184  
185 =head1 LICENSE AND COPYRIGHT
186  
187 Copyright 2012-2013 Jerry Lundström.
188  
189 This program is free software; you can redistribute it and/or modify it
190 under the terms of either: the GNU General Public License as published
191 by the Free Software Foundation; or the Artistic License.
192  
193 See http://dev.perl.org/licenses/ for more information.
194  
195  
196 =cut
197  
198 5 1; # End of Lim::RPC::Callback
« Lim/RPC/Transport.pm ↑ Summary Lim/Agent/CLI.pm »