lib/Mail/DMARC/Report/Aggregate/Record/Auth_Results/SPF.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 61.5% 16 / 26 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 5 totaltotal 75.2% 82 / 109 CC 21 SCAR 16.0
CC
21
Cov
79%
is_valid
12.2
new
5.0
scope
4.2
CRAP 5.0
« lib/Mail/DMARC/Report/Store/SQL/Grammars/MySQL.pm ↑ Summary lib/Mail/DMARC/Report/Send/SMTP.pm »
1 package Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF;
2 17 our $VERSION = '2.20261110';
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶no warnings 'experimental::args_array_with_signatures'; ## no critic (ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use parent 'Mail::DMARC::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 133 ▶sub new( $class, @args ) {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
12  
13 133 my $self = bless {}, $class;
14  
15 133 ▶ if ( !@args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 1 132 133
16 1 return $self;
17 }
18  
19 # a bare hash
20 132 ▶ return $self->_from_hash(@args) if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 7 125 132
21  
22 125 my $spf = shift @args;
23 125 ▶ return $spf if ref $spf eq $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $spf eq $class 18 107 125
24  
25 107 ▶ return $self->_from_hashref($spf) if 'HASH' eq ref $spf;
Branch: 1 branch
BranchTrueFalseTotal
if "HASH" eq ref $spf 107 0 107
26  
27 0 croak "invalid spf argument";
28 }
29  
30 113 ▶sub domain( $self, $value = undef ) {
Subroutine domain: called CC=3 SCAR=11.2
Pod undocumented
31 113 ▶ return $self->{domain} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 113 113
32 113 return $self->{domain} = lc $value;
33 }
34  
35 115 ▶sub result( $self, $value = undef ) {
Subroutine result: called CC=4 SCAR=13.9
Pod undocumented
36 115 ▶ return $self->{result} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 115 115
37 115 ▶ croak if !$self->is_valid_spf_result($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_spf_result($value) 1 114 115
38 114 return $self->{result} = $value;
39 }
40  
41 113 ▶sub scope( $self, $value = undef ) {
Subroutine scope: called CC=4 SCAR=14.5
Pod undocumented
42 113 ▶ return $self->{scope} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 113 113
43 113 ▶ croak if !$self->is_valid_spf_scope($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_spf_scope($value) 0 113 113
44 113 return $self->{scope} = $value;
45 }
46  
47 114 ▶sub _from_hash( $self, %args ) {
Subroutine _from_hash: called CC=4 SCAR=14.2
48  
49 113 foreach my $key ( keys %args ) {
50  
51 # scope is frequently absent on received reports
52 339 ▶ next if ( $key eq 'scope' && !$args{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "scope" and not $args{$key} 0 339 339
Condition66%2/3
$key eq "scope" and not $args{$key}
!ll&&!rl&&r
2261130
MC/DC0%0/2
$key eq "scope" and not $args{$key}
$key eq "scope" not $args{$key}
Truth table66%2/3
A and not(B)
A= $key eq "scope"B= not $args{$key}
ABresult
0X0
100
111
53 339 $self->$key( $args{$key} );
54 }
55  
56 113 $self->is_valid;
57 113 return $self;
58 }
59  
60 107 ▶sub _from_hashref( $self, $spf ) {
Subroutine _from_hashref: called CC=1 SCAR=0.0
61 107 return $self->_from_hash( %{$spf} );
62 }
63  
64 113 ▶sub is_valid($self) {
Subroutine is_valid: called CC=6 SCAR=25.0
Pod undocumented
65  
66 113 foreach my $f (qw/ domain result scope /) {
67 339 ▶ next if $self->{$f};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$f} 339 0 339
68 0 ▶ if ( $f ne 'scope' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f ne "scope") 0 0 0
69  
70 # quite a few DMARC reporters don't include scope
71 0 warn "SPF $f is required but missing!\n";
72 }
73 0 return 0;
74 }
75  
76 113 ▶ if ( $self->{result} =~ /^pass$/i && !$self->{domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"result"} =~ /^pass$/i and not $self->{"domain"}) 0 113 113
Condition66%2/3
$self->{"result"} =~ /^pass$/i and not $self->{"domain"}
!ll&&!rl&&r
23900
MC/DC0%0/2
$self->{"result"} =~ /^pass$/i and not $self->{"domain"}
$self->{"result"} =~ /^pass$/i not $self->{"domain"}
Truth table66%2/3
A and not(B)
A= $self->{"result"} =~ /^pass$/iB= not $self->{"domain"}
ABresult
0X0
100
111
77 0 warn "SPF pass MUST include the RFC5321.MailFrom domain!\n";
78 0 return 0;
79 }
80  
81 113 return 1;
82 }
83  
84 17 1;
85  
86 __END__
« lib/Mail/DMARC/Report/Store/SQL/Grammars/MySQL.pm ↑ Summary lib/Mail/DMARC/Report/Send/SMTP.pm »