Mail::SPF::Record(3)

πŸ’– Mail::SPF::Record πŸ’–

okay so bestie, welcome to Mail::SPF::Record β€” straight outta the User Contributed Perl Documentation, and yes it's giving "I'm an abstract base class and I know it" energy. Let's get into it πŸ’…


✨ NAME ✨

Mail::SPF::Record β€” abstract base class for SPF records πŸŽ€


✨ VERSION ✨

version 3.20260331 ✨ (fresh, no cap)


✨ SYNOPSIS ✨

🌸 creating a record from a string

use Mail::SPF::v1::Record;

my $record = Mail::SPF::v1::Record->new_from_string("v=spf1 a mx -all");

πŸ¦‹ creating a record synthetically

use Mail::SPF::v2::Record;

my $record = Mail::SPF::v2::Record->new(
    scopes      => ['mfrom', 'pra'],
    terms       => [
        Mail::SPF::Mech::A->new(),
        Mail::SPF::Mech::MX->new(),
        Mail::SPF::Mech::All->new(qualifier => '-')
    ],
    global_mods => [
        Mail::SPF::Mod::Exp->new(domain_spec => 'spf-exp.example.com')
    ]
);

✨ DESCRIPTION ✨

so Mail::SPF::Record is an abstract base class for SPF records. and here's the tea: you literally cannot instantiate it directly. it's not gonna happen, it's not the vibe. you have to make an instance of a concrete sub-class instead, okay? 🫢


πŸŽ€ Constructor πŸŽ€

the constructors we've got on deck:

  • new(%options): returns Mail::SPF::Record β€” makes you a brand new SPF record object ✨

%options is a list of key/value pairs, and it can be any of these cuties:

  • text β€” a string that's the unparsed text of the record πŸ“
  • scopes β€” a reference to an array of strings, denoting the scopes that the record covers (peep the description of the "scope" option on Mail::SPF::Request's "new" constructor if you need the lore)
  • terms β€” a reference to an array of Mail::SPF::Term objects (so like, Mail::SPF::Mech or Mail::SPF::Mod) that make up the record. do NOT put Mail::SPF::GlobalMod objects in here β€” those go in the "global_mods" option instead, bestie, I'm begging 😭
  • global_mods β€” a reference to an array of Mail::SPF::GlobalMod objects that are global modifiers of the record πŸ’œ
  • new_from_string($text, %options): returns Mail::SPF::Record; throws Mail::SPF::ENothingToParse, Mail::SPF::EInvalidRecordVersion, Mail::SPF::ESyntaxError β€” makes a new SPF record object by parsing the string plus whatever options you handed it 🌈

🧚 Class methods 🧚

these are the class methods, iconic behavior only:

  • version_tag_pattern: returns Regexp β€” Abstract. returns a regular expression that matches a legal version tag. this method is abstract, so sub-classes of Mail::SPF::Record must implement it, no skipping πŸ’…
  • default_qualifier: returns string β€” returns the default qualifier, i.e. '+' ⭐
  • results_by_qualifier: returns hash of string β€” returns a reference to a hash that maps qualifiers to result codes, like this:
    Qualifier | Result code
   -----------+-------------
        +     | pass
        -     | fail
        ~     | softfail
        ?     | neutral

πŸ’œ Instance methods πŸ’œ

and now the instance methods, the main characters:

  • text: returns string; throws Mail::SPF::ENoUnparsedText β€” returns the unparsed text of the record. but heads up: it throws a Mail::SPF::ENoUnparsedText exception if the record was created synthetically instead of being parsed, and no text was provided πŸ™ˆ
  • version_tag: returns string β€” Abstract. returns the version tag of the record. again, abstract! sub-classes of Mail::SPF::Record must implement it, periodt βœ‹
  • scopes: returns list of string β€” returns a list of the scopes the record covers. go read the description of the "new" constructor's "scopes" option for the full story πŸŽ€
  • terms: returns list of Mail::SPF::Term β€” returns a list of the terms that make up the record, excluding any global modifiers (those get returned by the "global_mods" method instead). see the description of the "new" constructor's "terms" option πŸ’«
  • global_mods: returns list of Mail::SPF::GlobalMod β€” returns a list of the record's global modifiers, ordered ascending by modifier precedence. see the description of the "new" constructor's "global_mods" option 🌸
  • global_mod($mod_name): returns Mail::SPF::GlobalMod β€” returns the global modifier with the given name if it's present in the record, and returns undef otherwise. use this one when you want one specific global modifier instead of collecting all of them like PokΓ©mon 🫢
  • stringify: returns string β€” returns the record's version tag and terms (global modifiers included, obviously) formatted as a string. and btw you can just use a Mail::SPF::Record object as a string for the exact same effect β€” see "OVERLOADING" below πŸ‘‘
  • eval($server, $request): throws Mail::SPF::Result β€” evaluates the SPF record in the context of the request parameters represented by the given Mail::SPF::Request object. the given Mail::SPF::Server object is what handles the DNS look-ups πŸ”₯. it throws a Mail::SPF::Result object matching the outcome of the evaluation β€” see Mail::SPF::Result. and for the exact algorithm used, go read RFC 4408, 4.6 and 4.7, iykyk πŸ“š

✨ OVERLOADING ✨

if you use a Mail::SPF::Record object as a string, the "stringify" method is what converts the object into a string. that's it, that's the whole section, slay πŸ’…


✨ SEE ALSO ✨

and for availability, support, and license info, go check the README file that ships with Mail::SPF πŸ“–


✨ AUTHORS ✨

Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> πŸ’–


and that's the whole page bestie!! this one came to you courtesy of perl v5.42.1 and it's dated 2026-04-23 β€” go forth and parse responsibly πŸŽ€βœ¨πŸ’…
πŸ“¦ where this page comes from