SPF/v1/Record.pm

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