| 1 | |||||||||||||||||||||||||||||||||||
| 2 | ############################################################################ | ||||||||||||||||||||||||||||||||||
| 3 | # base class for packet flows | ||||||||||||||||||||||||||||||||||
| 4 | ############################################################################ | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | package Net::Inspect::Flow; | ||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use fields qw(upper_flow); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||||||||
| 13 | 30 | ▶ | my ($class,$flow) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 14 | 30 | ▶ | if ( ! ref($class)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 15 | # create new | ||||||||||||||||||||||||||||||||||
| 16 | 2 | my $self = fields::new($class); | |||||||||||||||||||||||||||||||||
| 17 | 2 | $self->{upper_flow} = $flow; | |||||||||||||||||||||||||||||||||
| 18 | 2 | return $self; | |||||||||||||||||||||||||||||||||
| 19 | } else { | ||||||||||||||||||||||||||||||||||
| 20 | 28 | my $self = fields::new(ref($class)); | |||||||||||||||||||||||||||||||||
| 21 | $self->{upper_flow} = $flow | ||||||||||||||||||||||||||||||||||
| 22 | 28 | ▶ | || ( $class->{upper_flow} && $class->{upper_flow}->new ); # clone | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
$flow || $class->{'upper_flow'} && $class->{'upper_flow'}->new
$class->{"upper_flow"} and $class->{"upper_flow"}->new
MC/DC0%0/3
$flow || $class->{'upper_flow'} && $class->{'upper_flow'}->new
$flow
$class->{"upper_flow"}
$class->{"upper_flow"}->new
Truth table0%0/4
A || B and C
A= $flowB= $class->{"upper_flow"}C= $class->{"upper_flow"}->new
| |||||||||||||||||||||||||||||||||||
| 23 | 28 | return $self; | |||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | sub new_any { | ||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
new_any: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 29 | 0 | return Net::Inspect::Flow::Any->new(@_) | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # does nothing per default | ||||||||||||||||||||||||||||||||||
| 33 | ▶ | sub expire {} | |||||||||||||||||||||||||||||||||
|
Subroutine
expire: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | package Net::Inspect::Flow::Any; | ||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use Digest::MD5 'md5_hex'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use fields qw(flows); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | sub new { | ||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ($class,@methods) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=35.6
| |||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (@methods) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | 0 | my $clname = "Net::Inspect::Flow::Any::". | |||||||||||||||||||||||||||||||||
| 43 | md5_hex(join("\0",sort @methods)); | ||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( ! UNIVERSAL::can($clname,'new') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | # dynamically create class | ||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | eval "package $clname; use base 'Net::Inspect::Flow::Any';1" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | or die $@; | ||||||||||||||||||||||||||||||||||
| 48 | 0 | for my $method (@methods) { | |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 50 | 0 | *{ "${clname}::$method" } = sub { | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 52 | # copy, might change due detach in GuessProtocol | ||||||||||||||||||||||||||||||||||
| 53 | 0 | my @flows = @{$self->{flows}}; | |||||||||||||||||||||||||||||||||
| 54 | 0 | for my $flow (@flows) { | |||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my @rv = $flow->$method(@_) or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | return @rv | ||||||||||||||||||||||||||||||||||
| 58 | 0 | } else { | |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | defined( my $rv = $flow->$method(@_)) or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | return $rv | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||||||||||||||||
| 64 | 0 | }; | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | 0 | return $clname->new; | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( ! ref $class ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = fields::new($class); | |||||||||||||||||||||||||||||||||
| 73 | 0 | $self->{flows} = []; | |||||||||||||||||||||||||||||||||
| 74 | 0 | return $self | |||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||
| 76 | 0 | my $self = fields::new(ref($class)); | |||||||||||||||||||||||||||||||||
| 77 | # clone attached flows | ||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{flows} = [ map { $_->new } @{ $class->{flows} } ]; | |||||||||||||||||||||||||||||||||
| 79 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | sub attach { | ||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my ($self,$flow) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
attach: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 85 | 0 | push @{ $self->{flows} }, $flow; | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | sub detach { | ||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($self,$flow) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
detach: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | @{ $self->{flows} } = grep { $_ != $flow } @{ $self->{flows} }; | |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | sub attached { | ||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
attached: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 95 | 0 | return @{ $self->{flows} } | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||||||