File Coverage

blib/lib/Net/Frame/Layer/CDP/DeviceId.pm
Criterion Covered Total %
statement 29 35 82.8
branch 3 6 50.0
condition n/a
subroutine 8 10 80.0
pod 6 6 100.0
total 46 57 80.7


line stmt bran cond sub pod time code
1             #
2             # $Id: DeviceId.pm 1640 2013-03-28 17:58:27Z VinsWorldcom $
3             #
4             package Net::Frame::Layer::CDP::DeviceId;
5 19     19   7892 use strict; use warnings;
  19     19   32  
  19         558  
  19         87  
  19         27  
  19         508  
6              
7 19     19   1048 use Net::Frame::Layer qw(:consts :subs);
  19         92666  
  19         4748  
8             our @ISA = qw(Net::Frame::Layer);
9              
10             our @AS = qw(
11             type
12             length
13             deviceId
14             );
15             __PACKAGE__->cgBuildIndices;
16             __PACKAGE__->cgBuildAccessorsScalar(\@AS);
17              
18             #no strict 'vars';
19              
20 19     19   923 use Net::Frame::Layer::CDP::Constants qw(:consts);
  19         29  
  19         11821  
21              
22             sub new {
23             shift->SUPER::new(
24 2     2 1 246 type => NF_CDP_TYPE_DEVICE_ID,
25             length => 6,
26             deviceId => 'R1',
27             @_,
28             );
29             }
30              
31             sub getLength {
32 0     0 1 0 my $self = shift;
33              
34 0         0 my $length = 4 + length($self->deviceId);
35              
36 0         0 return $length
37             }
38              
39             sub pack {
40 1     1 1 223 my $self = shift;
41              
42 1 50       5 my $raw = $self->SUPER::pack('nna*',
43             $self->type,
44             $self->length,
45             $self->deviceId,
46             ) or return;
47              
48 1         65 return $self->raw($raw);
49             }
50              
51             sub unpack {
52 1     1 1 13 my $self = shift;
53              
54 1 50       5 my ($type, $length, $tail) =
55             $self->SUPER::unpack('nna*', $self->raw)
56             or return;
57              
58 1         27 $self->type($type);
59 1         10 $self->length($length);
60              
61 1         8 my $valLen = $length - 4;
62 1 50       7 my ($deviceId, $payload) =
63             $self->SUPER::unpack("a$valLen a*", $tail)
64             or return;
65              
66 1         12 $self->deviceId($deviceId);
67 1         13 $self->payload($payload);
68              
69 1         9 return $self;
70             }
71              
72             sub computeLengths {
73 0     0 1 0 my $self = shift;
74              
75 0         0 $self->length(4 + length($self->deviceId));
76              
77 0         0 return 1;
78             }
79              
80             sub print {
81 3     3 1 10 my $self = shift;
82              
83 3         22 my $l = $self->layer;
84 3         27 my $buf = sprintf
85             "$l: type:0x%04x length:%d deviceId:%s",
86             $self->type, $self->length, $self->deviceId;
87              
88 3         466 return $buf;
89             }
90              
91             1;
92              
93             __END__