SPF/v1/Record.pm

filter: Statementstmt 85.0% 34 / 40 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 90.9% 10 / 11 Podpod 100% 1 / 1 totaltotal 60.0% 45 / 75 CC 8 SCAR 34.8
CC
8
Cov
59%
new
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 32.6
« SPF/Record.pm ↑ Summary SPF/Mech.pm »
1 #
2 # Mail::SPF::v1::Record
3 # SPFv1 record class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Record.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::v1::Record;
12  
13 =head1 NAME
14  
15 Mail::SPF::v1::Record - SPFv1 record class
16  
17 =head1 VERSION
18  
19 version 3.20250505
20  
21 =cut
22  
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use base 'Mail::SPF::Record';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 use constant mech_classes => {
32 all => 'Mail::SPF::Mech::All',
33 ip4 => 'Mail::SPF::Mech::IP4',
34 ip6 => 'Mail::SPF::Mech::IP6',
35 a => 'Mail::SPF::Mech::A',
36 mx => 'Mail::SPF::Mech::MX',
37 ptr => 'Mail::SPF::Mech::PTR',
38 'exists' => 'Mail::SPF::Mech::Exists',
39 include => 'Mail::SPF::Mech::Include'
40 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 use constant mod_classes => {
43 redirect => 'Mail::SPF::Mod::Redirect',
44 'exp' => 'Mail::SPF::Mod::Exp'
45 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 eval("require $_")
48 1 foreach values(%{mech_classes()}), values(%{mod_classes()});
49  
50 1 ▶use constant version_tag => 'v=spf1';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use constant version_tag_pattern => qr/ v=spf(1) (?= \x20 | $ ) /ix;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 1 ▶use constant scopes => ('helo', 'mfrom');
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 =head1 SYNOPSIS
56  
57 See L<Mail::SPF::Record>.
58  
59 =head1 DESCRIPTION
60  
61 An object of class B<Mail::SPF::v1::Record> represents an B<SPFv1> (C<v=spf1>)
62 record.
63  
64 =head2 Constructors
65  
66 The following constructors are provided:
67  
68 =over
69  
70 =item B<new(%options)>: returns I<Mail::SPF::v1::Record>
71  
72 Creates a new SPFv1 record object.
73  
74 %options is a list of key/value pairs representing any of the following
75 options:
76  
77 =over
78  
79 =item B<text>
80  
81 =item B<terms>
82  
83 =item B<global_mods>
84  
85 See L<Mail::SPF::Record/new>.
86  
87 =item B<scopes>
88  
89 See L<Mail::SPF::Record/new>. Since SPFv1 records always implicitly cover the
90 C<helo> and C<mfrom> scopes, this option must either be exactly B<['helo',
91 'mfrom']> (or B<['mfrom', 'helo']>) or be omitted.
92  
93 =back
94  
95 =cut
96  
97 sub new {
98 0 ▶ my ($self, %options) = @_;
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
99 0 $self = $self->SUPER::new(%options);
100  
101 0 ▶ if (defined(my $scopes = $self->{scopes})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $scopes = $self->{"scopes"})) 0 0 0
102 0 ▶ @$scopes > 0
Branch: 1 branch
BranchTrueFalseTotal
@$scopes > 0 or "Mail::SPF::EInvalidScope"->throw("No scopes for v=spf1 record") 0 0 0
103 or throw Mail::SPF::EInvalidScope('No scopes for v=spf1 record');
104 0 ▶ @$scopes == 2 and
Branch: 1 branch
BranchTrueFalseTotal
@$scopes == 2 and $scopes->[0] eq "help" && $scopes->[1] eq "mfrom" || $scopes->[0] eq "mfrom" && $scopes->[1] eq "help" or "Mail::SPF::EInvalidScope"->throw('Invalid set of scopes ' . join(", ", map(("'${_}'"), @$scopes)) . ' for v=spf1 record') 0 0 0
Condition0%0/12
@$scopes == 2 and $scopes->[0] eq "help" && $scopes->[1] eq "mfrom" || $scopes->[0] eq "mfrom" && $scopes->[1] eq "help"
!ll&&!rl&&r
000
$scopes->[0] eq "help" and $scopes->[1] eq "mfrom" or $scopes->[0] eq "mfrom" and $scopes->[1] eq "help"
l!l&&r!l&&!r
000
$scopes->[0] eq "help" and $scopes->[1] eq "mfrom"
!ll&&!rl&&r
000
$scopes->[0] eq "mfrom" and $scopes->[1] eq "help"
!ll&&!rl&&r
000
MC/DC0%0/5
@$scopes == 2 and $scopes->[0] eq "help" && $scopes->[1] eq "mfrom" || $scopes->[0] eq "mfrom" && $scopes->[1] eq "help"
@$scopes == 2 $scopes->[0] eq "help" $scopes->[1] eq "mfrom" $scopes->[0] eq "mfrom" $scopes->[1] eq "help"
Truth table0%0/8
A and B and C or D and E
A= @$scopes == 2B= $scopes->[0] eq "help"C= $scopes->[1] eq "mfrom"D= $scopes->[0] eq "mfrom"E= $scopes->[1] eq "help"
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
105 (
106 $scopes->[0] eq 'help' and $scopes->[1] eq 'mfrom' or
107 $scopes->[0] eq 'mfrom' and $scopes->[1] eq 'help'
108 )
109 or throw Mail::SPF::EInvalidScope(
110 "Invalid set of scopes " . join(', ', map("'$_'", @$scopes)) . " for v=spf1 record");
111 }
112  
113 0 return $self;
114 }
115  
116 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::v1::Record>;
117 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidRecordVersion>,
118 I<Mail::SPF::ESyntaxError>
119  
120 Creates a new SPFv1 record object by parsing the string and any options given.
121  
122 =back
123  
124 =head2 Class methods
125  
126 The following class methods are provided:
127  
128 =over
129  
130 =item B<version_tag_pattern>: returns I<Regexp>
131  
132 Returns a regular expression that matches a version tag of B<'v=spf1'>.
133  
134 =item B<default_qualifier>
135  
136 =item B<results_by_qualifier>
137  
138 See L<Mail::SPF::Record/Class methods>.
139  
140 =back
141  
142 =head2 Instance methods
143  
144 The following instance methods are provided:
145  
146 =over
147  
148 =item B<text>
149  
150 =item B<scopes>
151  
152 =item B<terms>
153  
154 =item B<global_mods>
155  
156 =item B<global_mod>
157  
158 =item B<stringify>
159  
160 =item B<eval>
161  
162 See L<Mail::SPF::Record/Instance methods>.
163  
164 =item B<version_tag>: returns I<string>
165  
166 Returns B<'v=spf1'>.
167  
168 =back
169  
170 =head1 SEE ALSO
171  
172 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>,
173 L<Mail::SPF::Mod>
174  
175 L<http://tools.ietf.org/html/rfc4408>
176  
177 For availability, support, and license information, see the README file
178 included with Mail::SPF.
179  
180 =head1 AUTHORS
181  
182 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
183  
184 =cut
185  
186 1 TRUE;
« SPF/Record.pm ↑ Summary SPF/Mech.pm »