NAME
Data::Validate::DNS::NAPTR::Regexp - Validate the NAPTR Regexp field per RFC 2915 / RFC 3403 Section 4
VERSION
version 0.007
SYNOPSIS
Functional API (uses globals!!):
use Data::Validate::DNS::NAPTR::Regexp;
# Using <<'EOF' to mirror master-file format exactly
my $regexp = <<'EOF';
!test(something)!\\1!i
EOF
# Kill newline
$regexp =~ s/\n//;
if (is_naptr_regexp($regexp)) {
print "Regexp '$regexp' is okay!";
} else {
print "Regexp '$regexp' is invalid: " . naptr_regexp_error();
}
# Output:
# Regexp '!test(something)!\\1!i' is okay!
Object API:
use Data::Validate::DNS::NAPTR::Regexp ();
my $v = Data::Validate::DNS::NAPTR::Regexp->new();
# Using <<'EOF' to mirror master-file format exactly
my $regexp = <<'EOF';
!test(something)!\\1!i
EOF
# Kill newline
$regexp =~ s/\n//;
if ($v->is_naptr_regexp($regexp)) {
print "Regexp '$regexp' is okay!";
} else {
print "Regexp '$regexp' is invalid: " . $v->naptr_regexp_error();
}
# Output:
# Regexp '!test(something)!\\1!i' is okay!
# $v->error() also works
DESCRIPTION
This module validates the Regexp field in the NAPTR DNS Resource Record as defined by RFC 2915 / RFC 3403 Section 4.
It assumes that the data is in master file format and suitable for use in a ISC BIND zone file.
It validates as much as possible, except the actual POSIX extended regular expression.
EXPORT
By default, "is_naptr_regexp" and "naptr_regexp_error" will be exported. If you're using the "OBJECT API", importing an empty list is recommended.
FUNCTIONAL API
Methods
is_naptr_regexp
is_naptr_regexp('some-string');
Returns a true value if the provided string is a valid Regexp for an NAPTR record. Returns false otherwise. To determine why a Regexp is invalid, see "naptr_regexp_error" below.
naptr_regexp_error
naptr_regexp_error();
Returns the last string error from a call to "is_naptr_regexp" above. This is only valid if "is_naptr_regexp" failed and returns a false value.
OBJECT API
This is the preferred method as the functional API uses globals.
Constructor
new
Data::Validate::DNS::NAPTR::Regexp->new(%args)
Currently no %args
are available but this may change in the future.
is_naptr_regexp
$v->is_naptr_regexp('some-string');
See "is_naptr_regexp" above.
naptr_regexp_error
$v->naptr_regexp_error();
See "naptr_regexp_error" above.
error
$v->error();
See "naptr_regexp_error" above.
NOTES
This lib validates the data in master-file format. In RFC 2915, there are examples like:
IN NAPTR 100 10 "" "" "/urn:cid:.+@([^\.]+\.)(.*)$/\2/i" .
To enter the above into a master-file, all backslashes must be escaped, and so it would look like this:
IN NAPTR 100 10 "" "" "/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i" .
To enter this manually into a Perl script and check it, you'd have to escape all backslashes AGAIN:
my $regexp = '/urn:cid:.+@([^\\\\.]+\\\\.)(.*)$/\\\\2/i';
Or, if you use a here doc, you can enter it just as you would if putting it in a zone file (but you must clean up the newline):
my $regexp = <<'EOF';
/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i
EOF
$regexp =~ s/\n//;
The single-quote characters around "EOF" above are necessary or the backslashes will be interpolated!
SEE ALSO
RFC 2915 - https://tools.ietf.org/html/rfc2915
RFC 3403 - Obsoletes RFC 2915 - https://tools.ietf.org/html/rfc3403
AUTHOR
Matthew Horsfall (alh) - <wolfsage@gmail.com>
CREDITS
The logic for this module was adapted from ISC's BIND - https://www.isc.org/software/bind.
COPYRIGHT AND LICENSE
Copyright (C) 2013 Dyn, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.9 or, at your option, any later version of Perl 5 you may have available.