| 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
| |||||||||||
| 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
| |||||||||||
| 25 | |||||||||||
| 26 | # Find the first non-whitespace segment | ||||||||||
| 27 | 14 | ▶ | $msg =~ /^(\S+)(\s+.+)?$/ or return undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 35 | |||||||||||
| 36 | # The rest of the line (if any) is the comment | ||||||||||
| 37 | 14 | $self->{comment} = ''; | |||||||||
| 38 | 14 | ▶ | if ( defined $2 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||