Lite/Channel.pm

filter: Statementstmt 93.6% 104 / 111 Branchbran 86.6% 26 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.4% 19 / 21 Podpod 100% 17 / 17 totaltotal 90.7% 167 / 184 CC 18 SCAR 10.9
CC
18
Cov
91%
initialize
7.0
peer_seqno
6.0
ans_message
3.0
CRAP 3.0
« Lite/BaseProfile.pm ↑ Summary
1 # $Id: Channel.pm,v 1.4 2003/09/11 19:57:31 davidb Exp $
2 #
3 # Copyright (C) 2003 Verisign, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 # USA
19  
20 package Net::BEEP::Lite::Channel;
21  
22 =head1 NAME
23  
24 Net::BEEP::Lite::Channel - a class for holding BEEP channel variables.
25  
26 =head1 DESCRIPTION
27  
28 This is a class that basically just hold various channel related variables. Most of the actual "action" methods are in C<Net::BEEP::Lite::Session>.
29  
30 =cut
31  
32 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 4 ▶use Net::BEEP::Lite::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # some constants:
39 4 my $MAX_MSGNO = 2147483648;
40 4 my $MAX_SEQNO = 4294967296;
41  
42 =head1 CONSTRUCTOR
43  
44 =over 4
45  
46 =item new( I<ARGS> )
47  
48 This is the main constructor. It takes a named parameter list as its
49 argument. See the I<initialize> method for a list of valid parameter
50 names.
51  
52 =back
53  
54 =cut
55  
56 7 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
57 7 my $this = shift;
58 7 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
070
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  
60 7 my $self = {};
61 7 bless $self, $class;
62  
63 7 $self->initialize(@_);
64  
65 7 $self;
66 }
67  
68 =head1 METHODS
69  
70 =over 4
71  
72 =item initialize( I<ARGS> )
73  
74 Initialize the object. This is generally called by the constructor
75 and subclasses. It takes the following named parameters:
76  
77 =over 4
78  
79 =item Number
80  
81 The channel number.
82  
83 =item Window
84  
85 The local window to start with. Default to 4096.
86  
87 =item Profile
88  
89 The profile implementation.
90  
91 =back
92  
93 =cut
94  
95 7 ▶sub initialize {
Subroutine initialize: called CC=7 SCAR=19.5
Pod documented
96 7 my $self = shift;
97 7 my %args = @_;
98  
99 # default a few things
100 7 $self->{debug} = 0;
101 7 $self->{trace} = 0;
102 7 $self->{profile} = undef;
103 7 $self->{seqno} = 0;
104 7 $self->{peer_seqno} = 0;
105 7 $self->{msgno} = 0;
106 7 $self->{local_window} = 4096;
107 7 $self->{remote_window} = 4096;
108 7 $self->{message} = undef;
109 7 $self->{ans_message} = {};
110 7 $self->{number} = -1;
111  
112 7 for (keys %args) {
113 28 my $val = $args{$_};
114  
115 28 ▶ /^number$/io and do {
Branch: 1 branch
BranchTrueFalseTotal
/^number$/io and do { $self->{"number"} = $val; next } 6 22 28
116 6 $self->{number} = $val;
117 6 next;
118 };
119 22 ▶ /^window$/io and do {
Branch: 1 branch
BranchTrueFalseTotal
/^window$/io and do { $self->local_window($val); next } 6 16 22
120 6 $self->local_window($val);
121 6 next;
122 };
123 16 ▶ /^profile/io and do {
Branch: 1 branch
BranchTrueFalseTotal
/^profile/io and do { $self->profile($val); next } 6 10 16
124 6 $self->profile($val);
125 6 next;
126 };
127 10 ▶ /^debug$/io and do {
Branch: 1 branch
BranchTrueFalseTotal
/^debug$/io and do { $self->{"debug"} = $val; next } 5 5 10
128 5 $self->{debug} = $val;
129 5 next;
130 };
131 5 ▶ /^trace$/io and do {
Branch: 1 branch
BranchTrueFalseTotal
/^trace$/io and do { $self->{"trace"} = $val; next } 5 0 5
132 5 $self->{trace} = $val;
133 5 next;
134 };
135 }
136 }
137  
138 =item profile([$val])
139  
140 Sets or returns the profile implementation object assoc. with this
141 channel (if any).
142  
143 =cut
144  
145 7 ▶sub profile {
Subroutine profile: called CC=2 SCAR=6.9
Pod documented
146 7 my $self = shift;
147 7 my $val = shift;
148  
149 7 ▶ $self->{profile} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 6 1 7
150 7 $self->{profile};
151 }
152  
153 =item seqno()
154  
155 Returns the current (sending) sequence number for this channel. Note
156 that this is the sequence number for octets being sent to the peer.
157  
158 =cut
159  
160 6 ▶sub seqno {
Subroutine seqno: called CC=1 SCAR=0.0
Pod documented
161 6 my $self = shift;
162  
163 6 $self->{seqno};
164 }
165  
166 =item update_seqno($length)
167  
168 Adds length to the current sequence number. This is done when frames
169 are written to the socket.
170  
171 =cut
172  
173 4 ▶sub update_seqno {
Subroutine update_seqno: called CC=1 SCAR=0.0
Pod documented
174 4 my $self = shift;
175 4 my $length = shift;
176  
177 4 $self->{seqno} += $length;
178 4 $self->{seqno} %= $MAX_SEQNO;
179 4 $self->{seqno};
180 }
181  
182 =item peer_seqno([$val])
183  
184 Returns (or sets and returns) the peer sequence number. This is (or
185 should be) the sequence number of the octet seen from the peer on this
186 channel. I.e., this should get updated when frames are read from the
187 socket. This value is primarily used in calculating SEQ frames to
188 send back to the peer (as the ackno.).
189  
190 =cut
191  
192 # NOTE: the design of this module does not actually need this to
193 # operate: acknos may be calculated directly from the last received
194 # frame. This exists so at some future point it can be used to detect
195 # channel corruption.
196 0 ▶sub peer_seqno {
Subroutine peer_seqno: not called CC=2 SCAR=17.9
Pod documented
197 0 my $self = shift;
198 0 my $val = shift;
199  
200 0 ▶ $self->{peer_seqno} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
201 0 $self->{peer_seqno};
202 }
203  
204  
205 =item msgno([$val])
206  
207 Sets or returns the current message number for this channel.
208  
209 =cut
210  
211 6 ▶sub msgno {
Subroutine msgno: called CC=2 SCAR=6.9
Pod documented
212 6 my $self = shift;
213 6 my $val = shift;
214  
215 6 ▶ $self->{msgno} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 5 1 6
216 6 $self->{msgno};
217 }
218  
219 =item next_msgno()
220  
221 Returns the current message number, then increments it.
222  
223 =cut
224  
225 5 ▶sub next_msgno {
Subroutine next_msgno: called CC=1 SCAR=0.0
Pod documented
226 5 my $self = shift;
227  
228 5 my $n = $self->{msgno};
229 5 $self->{msgno}++;
230  
231 5 $self->{msgno} %= $MAX_MSGNO;
232 5 $n;
233 }
234  
235 =item local_window([$val])
236  
237 Sets or returns the size of the local (receiving) window. This is
238 what gets published in sent SEQ frames for this window.
239  
240 =cut
241  
242 8 ▶sub local_window {
Subroutine local_window: called CC=2 SCAR=6.9
Pod documented
243 8 my $self = shift;
244 8 my $val = shift;
245  
246 8 ▶ $self->{local_window} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 7 1 8
247 8 $self->{local_window};
248 }
249  
250 =item remote_window([$val])
251  
252 Sets or returns the size of the remove (sending) window. This is what
253 is used to determine the max payload size on a frame that is about to
254 be sent.
255  
256 =cut
257  
258 2 ▶sub remote_window {
Subroutine remote_window: called CC=2 SCAR=6.9
Pod documented
259 2 my $self = shift;
260 2 my $val = shift;
261  
262 2 ▶ $self->{remote_window} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 1 1 2
263 2 $self->{remote_window};
264 }
265  
266  
267 =item message()
268  
269 Returns the current message that is under construction by the recv_* method in C<Net::BEEP::Lite::Session>.
270  
271 =cut
272  
273 6 ▶sub message {
Subroutine message: called CC=2 SCAR=6.9
Pod documented
274 6 my $self = shift;
275 6 my $val = shift;
276  
277 6 ▶ $self->{message} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1 5 6
278 6 $self->{message};
279 }
280  
281 =item message_add_frame($frame)
282  
283 Adds (or create a new message with) the frame to the message under
284 construction.
285  
286 =cut
287  
288 2 ▶sub message_add_frame {
Subroutine message_add_frame: called CC=2 SCAR=6.9
Pod documented
289 2 my $self = shift;
290 2 my $frame = shift;
291  
292 2 ▶ if (not $self->message()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->message) { } 1 1 2
293 $self->message(new Net::BEEP::Lite::Message(Frame => $frame,
294 Debug => $self->{debug},
295 1 Trace => $self->{trace}));
296 } else {
297 1 $self->message()->add_frame($frame);
298 }
299 }
300  
301 =item clear_message()
302  
303 Clears the message under construction. This is generally done when the
304 message is complete.
305  
306 =cut
307  
308 1 ▶sub clear_message {
Subroutine clear_message: called CC=1 SCAR=0.0
Pod documented
309 1 my $self = shift;
310  
311 1 $self->{message} = undef;
312 }
313  
314 =item ans_message($ans_number, [$val])
315  
316 Returns or sets the ANS message under construction for the given ANS
317 number.
318  
319 =cut
320  
321 5 ▶sub ans_message {
Subroutine ans_message: called CC=3 SCAR=11.0
Pod documented
322 5 my $self = shift;
323 5 my $ansno = shift;
324 5 my $val = shift;
325  
326 5 ▶ return undef if not defined $ansno;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ansno 0 5 5
327 5 ▶ $self->{ans_message}->{$ansno} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1 4 5
328 5 $self->{ans_message}->{$ansno};
329 }
330  
331 =item ans_message_add_frame($frame)
332  
333 Adds a frame (or creates a new ANS message) for the ANS message under
334 construction with the frame's ANS number.
335  
336 =cut
337  
338 2 ▶sub ans_message_add_frame {
Subroutine ans_message_add_frame: called CC=2 SCAR=6.9
Pod documented
339 2 my $self = shift;
340 2 my $frame = shift;
341  
342 2 my $ansno = $frame->ansno();
343  
344 2 ▶ if (not $self->ans_message($ansno)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->ans_message($ansno)) { } 1 1 2
345 $self->ans_message($ansno, new Net::BEEP::Lite::Message
346 (Frame => $frame,
347 Debug => $self->{debug},
348 1 Trace => $self->{trace}));
349 } else {
350 1 $self->ans_message($ansno)->add_frame($frame);
351 }
352 }
353  
354 =item ans_clear_message($ans_number)
355  
356 Clears the ANS message under construction with the given ANS number.
357 This is generally done when the message is complete.
358  
359 =cut
360  
361 0 ▶sub ans_clear_message {
Subroutine ans_clear_message: not called CC=1 SCAR=6.9
Pod documented
362 0 my $self = shift;
363 0 my $ansno = shift;
364  
365 0 $self->{ans_message}->{$ansno} = undef;
366 }
367  
368 =item number()
369  
370 Returns the channel number.
371  
372 =cut
373  
374 1 ▶sub number {
Subroutine number: called CC=1 SCAR=0.0
Pod documented
375 1 my $self = shift;
376  
377 1 $self->{number};
378 }
379  
380 =pod
381  
382 =back
383  
384 =head1 SEE ALSO
385  
386 =over 4
387  
388 =item L<Net::BEEP::Lite::Session>
389  
390 =item L<Net::BEEP::Lite::Message>
391  
392 =back
393  
394 =cut
395  
396 4 1;
« Lite/BaseProfile.pm ↑ Summary