ThreatNet/Message/IPv4.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 25.0% 1 / 4 totaltotal 76.7% 43 / 56 CC 7 SCAR 14.1
CC
7
Cov
81%
new
7.8
comment
2.0
__as_Net_IP
2.0
CRAP 4.1
« ThreatNet/Filter/ThreatCache.pm ↑ Summary ThreatNet/Filter/Network.pm »
1 package ThreatNet::Message::IPv4;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use base 'ThreatNet::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Net::IP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 $VERSION = '0.20';
10 }
11  
12  
13  
14  
15  
16 #####################################################################
17 # Constructor and Accessors
18  
19 19 ▶sub new {
Subroutine new: called CC=7 SCAR=20.5
Pod documented
20 19 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 19 19
21 19 my $msg = shift;
22  
23 # Create the basic object from out parent class
24 19 ▶ my $self = $class->SUPER::new($msg) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $class->SUPER::new($msg) or return undef 14 5 19
25  
26 # Find the first non-whitespace segment
27 14 ▶ $msg =~ /^(\S+)(\s+.+)?$/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ /^(\S+)(\s+.+)?$/ or return undef 14 0 14
28  
29 # Net::IP supports a variety of different formats.
30 # We, on the other hand, don't.
31 # Run a basic check to ensure the format is generally correct.
32 # If we find at least one dot, then it won't be misrecognised.
33 14 my $ip = $1;
34 14 ▶ $ip =~ /\./ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ /\./ or return undef 14 0 14
35  
36 # The rest of the line (if any) is the comment
37 14 $self->{comment} = '';
38 14 ▶ if ( defined $2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 0 14 14
39 0 $self->{comment} = $2;
40 0 $self->{comment} =~ s/^\s+//;
41 }
42  
43 # Complete the creation of the IP and message
44 14 ▶ $self->{IP} = Net::IP->new( $ip, 4 ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"IP"} = "Net::IP"->new($ip, 4) or return undef 13 1 14
45  
46 13 $self;
47 }
48  
49 22 ▶sub IP { $_[0]->{IP} }
Subroutine IP: called CC=1 SCAR=0.0
Pod undocumented
50  
51 19 ▶sub ip { $_[0]->IP->ip }
Subroutine ip: called CC=1 SCAR=0.0
Pod undocumented
52  
53 0 ▶sub comment { $_[0]->{comment} }
Subroutine comment: not called CC=1 SCAR=6.9
Pod undocumented
54  
55  
56  
57  
58  
59 #####################################################################
60 # Param::Coerce Support
61  
62 0 ▶sub __as_Net_IP { $_[0]->IP }
Subroutine __as_Net_IP: not called CC=1 SCAR=6.9
63  
64 4 1;
« ThreatNet/Filter/ThreatCache.pm ↑ Summary ThreatNet/Filter/Network.pm »