Data::Validate::DNS::NAPTR::Regexp - Validate the NAPTR Regexp field per RFC 2915 / RFC 3403 Section 4
version 0.007
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
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.
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.
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();
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.
This is the preferred method as the functional API uses globals.
Data::Validate::DNS::NAPTR::Regexp->new(%args)
Currently no %args are available but this may change in the future.
%args
$v->is_naptr_regexp('some-string');
See "is_naptr_regexp" above.
$v->naptr_regexp_error();
See "naptr_regexp_error" above.
$v->error();
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!
RFC 2915 - https://tools.ietf.org/html/rfc2915
RFC 3403 - Obsoletes RFC 2915 - https://tools.ietf.org/html/rfc3403
Matthew Horsfall (alh) - <wolfsage@gmail.com>
The logic for this module was adapted from ISC's BIND - https://www.isc.org/software/bind.
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.
To install Data::Validate::DNS::NAPTR::Regexp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Validate::DNS::NAPTR::Regexp
CPAN shell
perl -MCPAN -e shell install Data::Validate::DNS::NAPTR::Regexp
For more information on module installation, please visit the detailed CPAN module installation guide.