Mail::SPF::Mech(3)

πŸ¦‹ NAME πŸ¦‹

okay so bestie, welcome to the man page for Mail::SPF::Mech β€” that's section 3 of the User Contributed Perl Documentation, and it's the SPF record mechanism base class. yes, base class. it's giving scaffolding, it's giving "we do the vibes, the subclasses do the work" πŸ’…


🌸 VERSION 🌸

version 3.20260331 β€” noted, screenshotted, memorized πŸ’–


πŸ’– DESCRIPTION πŸ’–

so, an object of class Mail::SPF::Mech represents a mechanism within an SPF record. that's the whole personality.

but here's the tea: Mail::SPF::Mech cannot be instantiated directly. nope. not happening. you have to create an instance of a concrete sub-class instead. it's abstract, it's mysterious, it's the main character who never shows up on screen 🫢


πŸŽ€ Constructors πŸŽ€

these are the constructors, bestie:

  • new(%options) β€” returns Mail::SPF::Mech

Abstract. Creates a new SPF record mechanism object.

%options is a list of key/value pairs representing any of the following options:

  • text β€” a string denoting the unparsed text of the mechanism.
  • qualifier β€” a single-character string denoting the qualifier of the mechanism. any of the following may be specified: '+' ("Pass"), '-' ("Fail"), '~' ("SoftFail"), '?' ("Neutral"). See RFC 4408, 4.6.2 and 2.5, for their meanings. defaults to '+' ✨
  • name β€” a string denoting the name of the mechanism. required if a generic Mail::SPF::Mech object (as opposed to a specific sub-class) is being constructed. like, you can't be anonymous here, tell us your name.
  • ip_network β€” a NetAddr::IP object denoting an optional IP address network parameter of the mechanism. can be either an IPv4 or an IPv6 address, with an optional network prefix length. IPv4-mapped IPv6 addresses (e.g. '::ffff:192.168.0.1') must not be specified directly, but as plain IPv4 addresses. no cap, do it the right way.
  • domain_spec β€” either a plain string or a Mail::SPF::MacroString object denoting an optional "domain-spec" parameter of the mechanism.
  • ipv4_prefix_length
  • ipv6_prefix_length

a string denoting an optional IPv4 or IPv6 network prefix length for the "domain_spec" of the mechanism. note that these options do not apply to the "ip_network" option, which already includes an optional network prefix length. yes bestie, read that twice, it's a whole trap πŸ™ˆ

other options may be specified by sub-classes of Mail::SPF::Mech.

  • new_from_string($text, %options) β€” returns Mail::SPF::Mech; throws Mail::SPF::ENothingToParse, Mail::SPF::EInvalidMech

Abstract. creates a new SPF record mechanism object by parsing the string and any options given. very "figure it out from the text" of it.


πŸ‘‘ Class methods πŸ‘‘

the following class methods are provided, periodt:

  • default_qualifier β€” returns string. returns the default qualifier, i.e. '+'. iconic, consistent, never changing.
  • default_ipv4_prefix_length β€” returns integer. returns the default IPv4 network prefix length, i.e. 32.
  • default_ipv6_prefix_length β€” returns integer. returns the default IPv6 network prefix length, i.e. 128.
  • qualifier_pattern β€” returns Regexp. returns a regular expression that matches any legal mechanism qualifier, i.e. '+', '-', '~', or '?'.
  • name β€” returns string. Abstract. returns the name of the mechanism.
this method is abstract and must be implemented by sub-classes of Mail::SPF::Mech. it's not optional, bestie, it's the assignment.
  • name_pattern β€” returns Regexp. returns a regular expression that matches any legal mechanism name.

🌈 Instance methods 🌈

and now the instance methods, the moment you've all been waiting for πŸ’–

  • text β€” returns string; throws Mail::SPF::ENoUnparsedText. returns the unparsed text of the mechanism. throws a Mail::SPF::ENoUnparsedText exception if the mechanism was created synthetically instead of being parsed, and no text was provided. so like, if you skipped the reading step, we notice 😭
  • qualifier β€” returns string. returns the qualifier of the mechanism. see the description of the "new" constructor's "qualifier" option. we already covered this, keep up 🫢
  • params β€” returns string. Abstract. returns the mechanism's parameters formatted as a string.
a sub-class of Mail::SPF::Mech does not have to implement this method if it supports no parameters. so if you have no params, you're off the hook, you're free, you're unbothered.
  • stringify β€” returns string. formats the mechanism's qualifier, name, and parameters as a string and returns it. (a qualifier that matches the default of '+' is omitted.) you can simply use a Mail::SPF::Mech object as a string for the same effect, see "OVERLOADING". it's giving "just use the object, it knows what to do".
  • domain($server, $request) β€” returns string. returns the target domain of the mechanism. depending on whether the mechanism does have an explicit "domain_spec" parameter, this is either the macro-expanded "domain_spec" parameter, or the request's authority domain (see "authority_domain" in Mail::SPF::Request) otherwise. both a Mail::SPF::Server and a Mail::SPF::Request object are required for resolving the target domain. bring both, or don't come at all.
  • match($server, $request) β€” returns boolean; throws Mail::SPF::Result::Error. Abstract. checks whether the mechanism matches the parameters of the given request (see Mail::SPF::Request) and returns true if it does, or false otherwise. in any case, takes both a Mail::SPF::Server and a Mail::SPF::Request object.
this method is abstract and must be implemented by sub-classes of Mail::SPF::Mech. yes, again. abstract. we said what we said πŸ’…
  • match_in_domain($server, $request) β€” returns boolean; throws Mail::SPF::Result::Error
  • match_in_domain($server, $request, $domain) β€” returns boolean; throws Mail::SPF::Result::Error

checks whether the mechanism's target domain name (that is, any of its DNS "A" or "AAAA" records) matches the given request's IP address (see "ip_address" in Mail::SPF::Request), and returns true if it does, or false otherwise. if an explicit domain is specified, it is used instead of the mechanism's target domain. the mechanism's IP network prefix lengths are respected when matching DNS address records against the request's IP address. see RFC 4408, 5, for the exact algorithm used. exact algorithm, bestie, we're not improvising

this method exists mainly for the convenience of sub-classes of Mail::SPF::Mech. it's a little gift, a little treat πŸŽ€
  • explain($server, $request, $result) β€” locally generates an explanation for why the mechanism caused the given result, and stores it in the given request object's state.
there is no need to override this method in sub-classes. see the "explanation_template" method. so don't touch it, it's handled.
  • explanation_template($server, $request, $result) β€” returns string. returns a macro string template for a locally generated explanation for why the mechanism caused the given result object.
sub-classes should either define an "explanation_templates_by_result_code" hash constant with their own templates, or override this method. pick a lane, both are valid 🌸

🫢 OVERLOADING 🫢

if a Mail::SPF::Mech object is used as a string, the "stringify" method is used to convert the object into a string. that's it, that's the whole section, it just works ✨


⭐ SEE ALSO ⭐

go read these too, they're all in the group chat:

  • Mail::SPF::Mech::All, Mail::SPF::Mech::IP4, Mail::SPF::Mech::IP6, Mail::SPF::Mech::A, Mail::SPF::Mech::MX, Mail::SPF::Mech::PTR, Mail::SPF::Mech::Exists, Mail::SPF::Mech::Include
  • Mail::SPF, Mail::SPF::Record, Mail::SPF::Term
  • <http://tools.ietf.org/html/rfc4408>

for availability, support, and license information, see the README file included with Mail::SPF. iykyk πŸ“„


πŸ’œ AUTHORS πŸ’œ

Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>


okay that's the whole page bestie, go forth and parse mechanisms responsibly πŸŒˆπŸ¦‹πŸ’–

perl v5.42.1 Β· 2026-04-23 Β· Mail::SPF::Mech(3) β€” mwah, that's a wrap πŸ’…βœ¨

πŸ“¦ where this page comes from