| 1 | # | ||||||||||
| 2 | # $Id: Layer.pm,v 1.7 2006/12/06 21:19:12 gomor Exp $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::Layer; | ||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 11 | require Class::Gomor::Array; | |||||||||
| 9 | 11 | require Exporter; | |||||||||
| 10 | 11 | our @ISA = qw(Class::Gomor::Array Exporter); | |||||||||
| 11 | |||||||||||
| 12 | 11 | our %EXPORT_TAGS = ( | |||||||||
| 13 | consts => [qw( | ||||||||||
| 14 | NP_LAYER_NONE | ||||||||||
| 15 | NP_LAYER_UNKNOWN | ||||||||||
| 16 | )], | ||||||||||
| 17 | ); | ||||||||||
| 18 | our @EXPORT_OK = ( | ||||||||||
| 19 | 11 | @{$EXPORT_TAGS{consts}}, | |||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 11 | ▶ | use constant NP_LAYER_NONE => undef; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 11 | ▶ | use constant NP_LAYER_UNKNOWN => 'UNKNOWN'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 11 | our @AS = qw( | |||||||||
| 26 | raw | ||||||||||
| 27 | payload | ||||||||||
| 28 | nextLayer | ||||||||||
| 29 | ); | ||||||||||
| 30 | 11 | __PACKAGE__->cgBuildIndices; | |||||||||
| 31 | 11 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 32 | |||||||||||
| 33 | 11 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 11 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 4 | ▶ | sub new { shift->SUPER::new(nextLayer => NP_LAYER_UNKNOWN, @_) } | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | |||||||||||
| 39 | sub layer { | ||||||||||
| 40 | 4 | ▶ | my $layer = ref(shift); | ||||||||
|
Subroutine
layer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 4 | $layer =~ s/^Net::Frame:://; | |||||||||
| 42 | 4 | $layer; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | # XXX: may use some optimizations | ||||||||||
| 46 | sub pack { | ||||||||||
| 47 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pack: called CC=2 SCAR=7.8
Pod
documented
| |||||||||||
| 48 | 3 | my ($fmt, @args) = @_; | |||||||||
| 49 | 3 | my $res; | |||||||||
| 50 | 3 | eval { $res = CORE::pack($fmt, @args) }; | |||||||||
| 51 | 3 | ▶ | $@ ? do { carp("@{[ref($self)]}: unable to pack structure\n"); undef } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | : $res; | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | sub unpack { | ||||||||||
| 56 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
unpack: called CC=2 SCAR=7.8
Pod
documented
| |||||||||||
| 57 | 3 | my ($fmt, $arg) = @_; | |||||||||
| 58 | 3 | my @res; | |||||||||
| 59 | 3 | eval { @res = CORE::unpack($fmt, $arg) }; | |||||||||
| 60 | 3 | ▶ | $@ ? do { carp("@{[ref($self)]}: unable to unpack structure\n"); () } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | : @res; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub getPayloadLength { | ||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
getPayloadLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 66 | 0 | ▶ | $self->payload ? length($self->payload) : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub encapsulate { NP_LAYER_NONE } | ||||||||
|
Subroutine
encapsulate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 70 | 0 | ▶ | sub computeLengths { 1 } | ||||||||
|
Subroutine
computeLengths: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | 0 | ▶ | sub computeChecksums { 1 } | ||||||||
|
Subroutine
computeChecksums: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 72 | 0 | ▶ | sub print { $self->layer.': to implement' } | ||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 0 | ▶ | sub getLength { 0 } | ||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 74 | |||||||||||
| 75 | sub dump { | ||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | my $hex = CORE::unpack('H*', $self->raw); | |||||||||
| 79 | 0 | my $l = $self->layer; | |||||||||
| 80 | 0 | sprintf "$l: $hex"; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 11 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||