NAME
Validate::SPF::Parser - SPF v1 parser implementation
VERSION
version 0.005
SYNOPSIS
use Validate::SPF::Parser;
$parser = Validate::SPF::Parser->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
...
}
METHODS
new
Creates an instance of SPF parser.
my $parser = Validate::SPF::Parser->new;
parse
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.
raise_error
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.
error
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
Please see those modules/websites for more information related to this module.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/Wu-Wu/Validate-SPF/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
Anton Gerasimov <chim@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Anton Gerasimov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.