Packet/CDP/TypePortId.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
pack
2.0
unpack
2.0
CRAP 2.0
1 #
2 # $Id: TypePortId.pm 2002 2015-02-15 16:50:35Z gomor $
3 #
4 package Net::Packet::CDP::TypePortId;
5 use strict;
6 use warnings;
7  
8 require Net::Packet::CDP::Type;
9 our @ISA = qw(Net::Packet::CDP::Type);
10  
11 use Net::Packet::Consts qw(:cdp);
12  
13 our @AS = qw(
14 sentThrough
15 );
16 __PACKAGE__->cgBuildIndices;
17 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
18  
19 #no strict 'vars';
20  
21 sub new {
22 shift->SUPER::new(
23 type => NP_CDP_TYPE_PORT_ID,
24 length => 8,
25 sentThrough => '1/4',
26 @_,
27 );
28 }
29  
30 sub pack {
31 my $self = shift;
32  
33 $self->raw($self->SUPER::pack('nnH*',
34 $self->type,
35 $self->length,
36 CORE::unpack('H*', $self->sentThrough),
37 )) or return undef;
38  
39 1;
40 }
41  
42 sub unpack {
43 my $self = shift;
44  
45 my ($type, $length, $tail) = $self->SUPER::unpack('nna*', $self->raw)
46 or return undef;
47  
48 $self->type($type);
49 $self->length($length);
50  
51 my $sentThroughLen = ($length - 4) * 2;
52  
53 my ($sentThrough, $payload) =
54 $self->SUPER::unpack("H$sentThroughLen a*", $tail)
55 or return undef;
56  
57 $self->type($type);
58 $self->length($length);
59 $self->sentThrough(CORE::pack('H*', $sentThrough));
60  
61 $self->payload($payload);
62  
63 1;
64 }
65  
66 sub print {
67 my $self = shift;
68  
69 my $i = $self->is;
70 my $l = $self->layer;
71 sprintf "$l: $i: type:0x%04x length:%d sentThrough:%s",
72 $self->type, $self->length, $self->sentThrough;
73 }
74  
75 1;
76  
77 __END__