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.pm ↑ Summary blib/lib/Mail/DMARC/Report/Aggregate/Record/Identifiers.pm »
1 package Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF;
2 17 our $VERSION = '2.20260827';
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 110 ▶sub new( $class, @args ) {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
12  
13 110 my $self = bless {}, $class;
14  
15 110 ▶ if ( !@args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 1 109 110
16 1 return $self;
17 }
18  
19 # a bare hash
20 109 ▶ return $self->_from_hash(@args) if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 7 102 109
21  
22 102 my $spf = shift @args;
23 102 ▶ return $spf if ref $spf eq $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $spf eq $class 16 86 102
24  
25 86 ▶ return $self->_from_hashref($spf) if 'HASH' eq ref $spf;
Branch: 1 branch
BranchTrueFalseTotal
if "HASH" eq ref $spf 86 0 86
26  
27 0 croak "invalid spf argument";
28 }
29  
30 92 ▶sub domain( $self, $value = undef ) {
Subroutine domain: called CC=3 SCAR=11.2
Pod undocumented
31 92 ▶ return $self->{domain} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 92 92
32 92 return $self->{domain} = lc $value;
33 }
34  
35 94 ▶sub result( $self, $value = undef ) {
Subroutine result: called CC=4 SCAR=13.9
Pod undocumented
36 94 ▶ return $self->{result} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 94 94
37 94 ▶ croak if !$self->is_valid_spf_result($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_spf_result($value) 1 93 94
38 93 return $self->{result} = $value;
39 }
40  
41 92 ▶sub scope( $self, $value = undef ) {
Subroutine scope: called CC=4 SCAR=14.5
Pod undocumented
42 92 ▶ return $self->{scope} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 92 92
43 92 ▶ croak if !$self->is_valid_spf_scope($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_spf_scope($value) 0 92 92
44 92 return $self->{scope} = $value;
45 }
46  
47 93 ▶sub _from_hash( $self, %args ) {
Subroutine _from_hash: called CC=4 SCAR=14.2
48  
49 92 foreach my $key ( keys %args ) {
50  
51 # scope is frequently absent on received reports
52 276 ▶ next if ( $key eq 'scope' && !$args{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "scope" and not $args{$key} 0 276 276
Condition66%2/3
$key eq "scope" and not $args{$key}
!ll&&!rl&&r
184920
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 276 $self->$key( $args{$key} );
54 }
55  
56 92 $self->is_valid;
57 92 return $self;
58 }
59  
60 86 ▶sub _from_hashref( $self, $spf ) {
Subroutine _from_hashref: called CC=1 SCAR=0.0
61 86 return $self->_from_hash( %{$spf} );
62 }
63  
64 92 ▶sub is_valid($self) {
Subroutine is_valid: called CC=6 SCAR=25.0
Pod undocumented
65  
66 92 foreach my $f (qw/ domain result scope /) {
67 276 ▶ next if $self->{$f};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$f} 276 0 276
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 92 ▶ if ( $self->{result} =~ /^pass$/i && !$self->{domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"result"} =~ /^pass$/i and not $self->{"domain"}) 0 92 92
Condition66%2/3
$self->{"result"} =~ /^pass$/i and not $self->{"domain"}
!ll&&!rl&&r
21710
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 92 return 1;
82 }
83  
84 17 1;
85  
86 __END__
87  
88 =pod
89  
90 =head1 NAME
91  
92 Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF - auth_results/spf section of a DMARC aggregate record
93  
94 =head1 VERSION
95  
96 version 2.20260827
97  
98 =head1 AUTHORS
99  
100 =over 4
101  
102 =item *
103  
104 Matt Simerson <msimerson@cpan.org>
105  
106 =item *
107  
108 Davide Migliavacca <shari@cpan.org>
109  
110 =item *
111  
112 Marc Bradshaw <marc@marcbradshaw.net>
113  
114 =back
115  
116 =head1 COPYRIGHT AND LICENSE
117  
118 This software is copyright (c) 2026 by Matt Simerson.
119  
120 This is free software; you can redistribute it and/or modify it under
121 the same terms as the Perl 5 programming language system itself.
122  
123 =cut
« lib/Mail/DMARC.pm ↑ Summary blib/lib/Mail/DMARC/Report/Aggregate/Record/Identifiers.pm »