| Net-DNS-Method documentation | Contained in the Net-DNS-Method distribution. |
Net::DNS::Method - Base class for Net::DNS::Server methods
use Net::DNS::Method;
package Net::DNS::Method::Sample;
our @ISA = qw( ... Net::DNS::Method ... );
sub new { ... }
sub A { ... }
This is a base class to help in the creation of method classes for use within the Net::DNS::Server package. This class provides specific methods to do nothing to particular DNS questions. In general, this class consists of a number of methods that are called like in the following example.
->A($q, $ans)This would be invoked by Net::DNS::Server upon the arrival of a query of type 'A'.
The method can check the question, passed as a Net::DNS::Qustion
object in $q. Usually, the method will then modify the
Net::DNS::Packet object in $ans to provide an answer.
Net::DNS::Server will call sequentially all of the registered Net::DNS::Method::* objects for a given question. After this sequence of calls ends, the response can be sent depending on what the methods have requsted.
The return value of the method is given as an OR of the following values.
NS_IGNORERequests that the current question be ignored.
NS_STOPRequests that no further objects be invoked.
NS_OKIndicates that the current method matched the question and presumably,
altered the answer. Control is passed to the next method in
sequence. After the last method is invoked, the answer will be sent to
the client unless NS_IGNORE is returned by this or a later method.
NS_FAILIndicates that the current method did not match the packet.
NS_SPLITIndicates that the response must be splitted in individual answers and sent accordingly. This is used for AXFR requests.
There is one such method for each type of RR supported by
Net::DNS. Additionally, the ->ANY method is provided, which
calls all the defined RRs in succession.
NS_* constants used for the return values.
$Id: Method.pm,v 1.2 2002/10/23 04:43:58 lem Exp $
NS_SPLIT.
Luis E. Munoz <luismunoz@cpan.org>
perl(1), Net::DNS(3), Net::DNS::Server(3), Net::DNS::Question(3), Net::DNS::Packet(3).
| Net-DNS-Method documentation | Contained in the Net-DNS-Method distribution. |
package Net::DNS::Method; require 5.005_62; use Carp; use strict; use warnings; no strict 'refs'; use vars qw/$AUTOLOAD/; use File::Find; use constant NS_FAIL => 0x00; use constant NS_OK => 0x01; use constant NS_STOP => 0x02; use constant NS_IGNORE => 0x04; use constant NS_SPLIT => 0x08; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( NS_OK NS_FAIL NS_STOP NS_IGNORE NS_SPLIT ); our $VERSION = '2.00'; sub new { croak "Net::DNS::Method is meant as a base class. Do not use it directly.\n"; } ## The AUTOLOAD below, handles the creation of methods that are to be defined ## to answer for each known RR type in Net::DNS. sub AUTOLOAD { my $sub = $AUTOLOAD; $sub =~ s/.*:://; *$sub = sub { NS_FAIL; }; goto &$sub; } ## The call to ANY will cause all the methods to be created. my @RR = (); sub ANY { my $self = shift; my $q = $_[0]; my $ans = $_[1]; unless (@RR) { find( { no_chdir => 1, wanted => sub { my $file = m/(\w+)\.pm$/ && $1; return undef unless $File::Find::dir =~ m!Net/DNS[^\w]!; push @RR, $file if $file; } }, grep { -d } @INC); } my $ret = NS_FAIL; for my $r (@RR) { $ret |= $self->$r(@_); } if (!($ret & NS_OK) and $ans->header->rcode eq 'NOERROR') { $ans->header->rcode('NXDOMAIN'); } return $ret; } 1; __END__ # Below is stub documentation for your module. You better edit it!