File Coverage

blib/lib/Mail/SPF/v1/Record.pm
Criterion Covered Total %
statement 30 36 83.3
branch 0 6 0.0
condition 0 6 0.0
subroutine 10 11 90.9
pod 1 1 100.0
total 41 60 68.3


line stmt bran cond sub pod time code
1             #
2             # Mail::SPF::v1::Record
3             # SPFv1 record class.
4             #
5             # (C) 2005-2012 Julian Mehnle
6             # 2005 Shevek
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     1   2319 use warnings;
  1         2  
  1         89  
24 1     1   9 use strict;
  1         3  
  1         37  
25              
26 1     1   6 use base 'Mail::SPF::Record';
  1         3  
  1         216  
27              
28 1     1   144 use constant TRUE => (0 == 0);
  1         5  
  1         198  
29 1     1   12 use constant FALSE => not TRUE;
  1         3  
  1         114  
30              
31 1         79 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     1   8 };
  1         3  
41              
42 1         109 use constant mod_classes => {
43             redirect => 'Mail::SPF::Mod::Redirect',
44             'exp' => 'Mail::SPF::Mod::Exp'
45 1     1   6 };
  1         3  
46              
47             eval("require $_")
48             foreach values(%{mech_classes()}), values(%{mod_classes()});
49              
50 1     1   7 use constant version_tag => 'v=spf1';
  1         3  
  1         107  
51 1     1   7 use constant version_tag_pattern => qr/ v=spf(1) (?= \x20 | $ ) /ix;
  1         2  
  1         100  
52              
53 1     1   7 use constant scopes => ('helo', 'mfrom');
  1         3  
  1         341  
54              
55             =head1 SYNOPSIS
56              
57             See L.
58              
59             =head1 DESCRIPTION
60              
61             An object of class B represents an B (C)
62             record.
63              
64             =head2 Constructors
65              
66             The following constructors are provided:
67              
68             =over
69              
70             =item B: returns I
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
80              
81             =item B
82              
83             =item B
84              
85             See L.
86              
87             =item B
88              
89             See L. Since SPFv1 records always implicitly cover the
90             C and C 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     0 1   my ($self, %options) = @_;
99 0           $self = $self->SUPER::new(%options);
100              
101 0 0         if (defined(my $scopes = $self->{scopes})) {
102 0 0         @$scopes > 0
103             or throw Mail::SPF::EInvalidScope('No scopes for v=spf1 record');
104 0 0 0       @$scopes == 2 and
      0        
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: returns I;
117             throws I, I,
118             I
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: returns I
131              
132             Returns a regular expression that matches a version tag of B<'v=spf1'>.
133              
134             =item B
135              
136             =item B
137              
138             See L.
139              
140             =back
141              
142             =head2 Instance methods
143              
144             The following instance methods are provided:
145              
146             =over
147              
148             =item B
149              
150             =item B
151              
152             =item B
153              
154             =item B
155              
156             =item B
157              
158             =item B
159              
160             =item B
161              
162             See L.
163              
164             =item B: returns I
165              
166             Returns B<'v=spf1'>.
167              
168             =back
169              
170             =head1 SEE ALSO
171              
172             L, L, L, L,
173             L
174              
175             L
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 , Shevek
183              
184             =cut
185              
186             TRUE;