blib/lib/Mail/DataFeed/Abusix.pm

filter: Statementstmt 79.3% 46 / 58 Branchbran 85.7% 12 / 14 Conditioncond 92.3% 12 / 13 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 83.3% 10 / 12 Podpod 100% 1 / 1 totaltotal 81.9% 86 / 105 SCAR 28.6
CC
16
Cov
82%
_build_report
13.0
_sockets
12.0
send
6.0
CRAP 17.4
↑ Summary
1 package Mail::DataFeed::Abusix;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use feature qw(postderef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶no warnings qw(experimental::postderef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: Send SMTP transaction data to the Abusix transaction feed
9 1 our $VERSION = '1.20200331.1'; ## VERSION
10 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has feed_name => ( is => 'ro', required => 1 );
14 1 has feed_key => ( is => 'ro', required => 1);
15 1 has feed_dest => ( is => 'ro', required => 1);
16  
17 1 has sockets => ( is => 'ro', lazy => 1, builder => '_sockets' );
18  
19 1 has port => ( is => 'rw' );
20 1 has ip_address => ( is => 'rw' );
21 1 has reverse_dns => ( is => 'rw' );
22 1 has helo => ( is => 'rw' );
23 1 has used_esmtp => ( is => 'rw', default => undef );
24 1 has used_tls => ( is => 'rw', default => undef );
25 1 has used_auth => ( is => 'rw', default => undef );
26 1 has mail_from_domain => ( is => 'rw' );
27  
28  
29  
30 sub _sockets {
31 0 ▶ my ($self) = @_;
Subroutine _sockets: not called CC=3 SCAR=24.8
32 0 my @sockets;
33 0 foreach my $dest ( split ',', $self->feed_dest ) {
34 0 my ( $peer_address, $peer_port ) = split(':', $dest, 2);
35 0 ▶ $peer_port = 12211 if !$peer_port;
Branch: 1 branch
BranchTrueFalseTotal
unless $peer_port 0 0 0
36 0 my $socket = IO::Socket::INET->new(
37 PeerAddr => $peer_address,
38 PeerPort => $peer_port,
39 Proto => 'udp',
40 Type => SOCK_DGRAM,
41 );
42 0 push @sockets, $socket;
43 }
44 0 return \@sockets;
45 }
46  
47  
48 sub send {
49 0 ▶ my ($self) = @_;
Subroutine send: not called CC=2 SCAR=17.9
Pod documented
50 0 my $report = $self->_build_report();
51 0 foreach my $socket ($self->sockets->@*) {
52 0 $socket->send($report);
53 }
54  
55 }
56  
57 sub _build_report {
58 25 ▶ my ($self,$args) = @_;
Subroutine _build_report: called CC=13 SCAR=25.7
59  
60 25 ▶ my $time = $args->{_time} // time(); # Ability to override time for testing!
Condition66%2/3
$args->{"_time"} // time
l!l&&r!l&&!r
2230
MC/DC0%0/2
$args->{"_time"} // time
$args->{"_time"} time
Truth table66%2/3
A // B
A= $args->{"_time"}B= time
ABresult
1X1
011
000
61 25 my $extended_json = ''; # Reserved for future use, should be empty.
62  
63 25 ▶ my $packet = join( "\n",
Branch: 6 branches
BranchTrueFalseTotal
!defined($self->used_esmtp) ? : 12 13 25
$self->used_esmtp ? : 3 10 13
!defined($self->used_tls) ? : 15 10 25
$self->used_tls ? : 3 7 10
!defined($self->used_auth) ? : 18 7 25
$self->used_auth ? : 1 6 7
Condition100%10/10
$self->port // ""
l!l
214
$self->ip_address // ""
l!l
196
$self->reverse_dns // ""
l!l
178
$self->helo // ""
l!l
1510
$self->mail_from_domain // ""
l!l
421
MC/DC100%1/1
$self->port // ""
$self->port
MC/DC100%1/1
$self->ip_address // ""
$self->ip_address
MC/DC100%1/1
$self->reverse_dns // ""
$self->reverse_dns
MC/DC100%1/1
$self->helo // ""
$self->helo
MC/DC100%1/1
$self->mail_from_domain // ""
$self->mail_from_domain
Truth table100%2/2
A
A= $self->port
Aresult
11
00
Truth table100%2/2
A
A= $self->ip_address
Aresult
11
00
Truth table100%2/2
A
A= $self->reverse_dns
Aresult
11
00
Truth table100%2/2
A
A= $self->helo
Aresult
11
00
Truth table100%2/2
A
A= $self->mail_from_domain
Aresult
11
00
64 $self->feed_name,
65 $time,
66 $self->port // '',
67 $self->ip_address // '',
68 $self->reverse_dns // '',
69 $self->helo // '',
70 !defined $self->used_esmtp ? '' : $self->used_esmtp ? 'Y' : 'N',
71 !defined $self->used_tls ? '' : $self->used_tls ? 'Y' : 'N',
72 !defined $self->used_auth ? '' : $self->used_auth ? 'Y' : 'N',
73 $self->mail_from_domain // '',
74 $extended_json,
75 );
76  
77 25 $packet = join( "\n",
78 $packet,
79 $self->_checksum($packet),
80 );
81  
82 25 return $packet;
83 }
84  
85 sub _checksum {
86 25 ▶ my ($self, $packet) = @_;
Subroutine _checksum: called CC=1 SCAR=0.0
87 25 my $checksum = md5_hex(join( "\n", $packet, $self->feed_key ));
88 25 return $checksum;
89 }
90  
91 1 1;
92  
93 __END__
↑ Summary