SYNOPSIS

use <<$package>>;

$parser = <<$package>>->new;
$ast = $parser->parse( 'v=spf1 a include:_spf.example.com ~all' );

unless ( $ast ) {
    # fail
    print "Error: " . $parser->error->{code} . ": " . $parser->error->{text} . "\n";
}
else {
    # ok
    ...
}

Creates an instance of SPF parser.

my $parser = <<$package>>->new;

Builds an abstract syntax tree (AST) for given text representation of SPF.

my $ast = $parser->parse( 'v=spf1 ~all' );

Returns an undef if error occured. See "error" for details.

Raises a parser error.

$parser->raise_error( $error_code, $context, @extra );
$parser->raise_error( 'E_FOO', 'context line', qw( bar baz ) );

Arguments are:

$error_code

Error code. If code does not exist in error table it will be replaced with "E_DEFAULT".

$context

Context line.

@extra

Extra parameters for error text.

Returns last error occured as HashRef.

$parser->error;

Here is an example

{
   code    => "E_DEFAULT",
   text    => "Just error",
   context => "",
}

ERROR HANDLING

The following errors might be returned.

E_SYNTAX

Syntax error. The marker pointed to errored token in context line. E.g.:

{
    code    => "E_SYNTAX",
    context => "v=spf1 <*>exclude:foo.example.com  mx ~all",
    text    => "Syntax error near token 'exclude'",
}

E_INVALID_VERSION

Returned in cases of version token does not equal spf1.

{
    code    => "E_INVALID_VERSION",
    text    => "Invalid SPF version",
    context => "v=spf2",
}

E_IPADDR_EXPECTED

Returned in cases of ip4 or ip6 token has been used without ip or network address.

{
    code    => "E_IPADDR_EXPECTED",
    text    => "Expected ip or network address",
    context => "ip4",
}

E_DOMAIN_EXPECTED

Returned in cases of exists or include token has been used without domain name.

{
    code    => "E_DOMAIN_EXPECTED",
    text    => "Expected domain name",
    context => "exists",
}

E_UNEXPECTED_BITMASK

Returned in cases of ptr or all token has been used with bitmask.

{
    code    => "E_UNEXPECTED_BITMASK",
    text    => "Unexpected bitmask",
    context => "?ptr:foo.net/18",
}

E_UNEXPECTED_IPADDR

Returned in cases of ptr or all token has been used with ip or network address.

{
    code    => "E_UNEXPECTED_IPADDR",
    text    => "Unexpected ip address",
    context => "-ptr:127.0.0.1",
}

E_UNEXPECTED_DOMAIN

Returned in cases of all token has been used with domain name.

{
    code    => "E_UNEXPECTED_DOMAIN",
    text    => "Unexpected domain name",
    context => "-all:quux.com",
}

E_DEFAULT

Default (last resort) error.

{
   code    => "E_DEFAULT",
   text    => "Just error",
   context => "",
}

BUILD PARSER

In cases of Parser.yp was modified you should re-build this module. Ensure you have Parse::Yapp distribution installed.

In root directory:

$ yapp -s -m Validate::SPF::Parser -o lib/Validate/SPF/Parser.pm -t Parser.pm.skel Parser.yp

Ensure the lib/Validate/SPF/Parser.pm saved without tab symbols and has unix line endings.

SEE ALSO

Parse::Yapp

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 45:

Unknown directive: =method

Around line 69:

Unknown directive: =method

Around line 77:

Unknown directive: =method

Around line 102:

Unknown directive: =method