| 1 | # Bind8 MX record handling | ||
| 2 | # | ||
| 3 | # Copyright Karthik Krishnamurthy <karthik.k@extremix.net> | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Unix::Conf::Bind8::DB::MX - Class representing MX records. | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | Refer to the SYNOPSIS section for Unix::Conf::Bind8::DB::Record. | ||
| 12 | |||
| 13 | =head1 METHODS | ||
| 14 | |||
| 15 | Methods specified here are overridden. They might or not be differnt from | ||
| 16 | the derived ones. For other methods refer to the METHODS section for | ||
| 17 | Unix::Conf::Bind8::DB::Record. | ||
| 18 | |||
| 19 | =over 4 | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | package Unix::Conf::Bind8::DB::MX; | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | use Unix::Conf; | ||
| 29 | use Unix::Conf::Bind8::DB::Lib; | ||
| 30 | use Unix::Conf::Bind8::DB::Record; | ||
| 31 | |||
| 32 | our (@ISA) = qw (Unix::Conf::Bind8::DB::Record); | ||
| 33 | |||
| 34 | =item new () | ||
| 35 | |||
| 36 | Arguments | ||
| 37 | LABEL => 'string', | ||
| 38 | CLASS => 'string', # 'IN'|'HS'|'CHAOS' | ||
| 39 | TTL => 'string'|number, | ||
| 40 | RTYPE => 'string', # 'A'|'NS'|'MX'|'SOA'|'CNAME'|'PTR' | ||
| 41 | MXPREF => mxpref # number | ||
| 42 | RDATA => data | ||
| 43 | PARENT => reference, # to the DB object datastructure | ||
| 44 | |||
| 45 | Class constructor. | ||
| 46 | Creates a new Unix::Conf::Bind8::DB::MX object and returns it | ||
| 47 | if successful, an Err object otherwise. Do not use this constructor | ||
| 48 | directly. Use the Unix::Conf::Bind8::DB::new_mx () equivalent instead. | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | # Override class constructor in base class. The difference is here we check | ||
| 53 | # to see argument MXPREF is defined and assign it. | ||
| 54 | |||
| 55 | sub new | ||
| 56 | { | ||
| 57 | my $class = shift (); | ||
| 58 | my %args = ( @_ ); | ||
| 59 | my $new = bless ({}, $class); | ||
| 60 | my $ret; | ||
| 61 | |||
| 62 | return (Unix::Conf->_err ('new', "MXPREF not specified")) | ||
| 63 | unless (defined ($args{MXPREF})); | ||
| 64 | return (Unix::Conf->_err ('new', "LABEL not specified")) | ||
| 65 | unless (defined ($args{LABEL})); | ||
| 66 | return (Unix::Conf->_err ('new', "RTYPE not specified")) | ||
| 67 | unless (defined ($args{RTYPE})); | ||
| 68 | return (Unix::Conf->_err ('new', "RDATA not specified")) | ||
| 69 | unless (defined ($args{RDATA})); | ||
| 70 | return (Unix::Conf->_err ('new', "PARENT not specified")) | ||
| 71 | unless (defined ($args{PARENT})); | ||
| 72 | |||
| 73 | $ret = $new->_parent ($args{PARENT}) or return ($ret); | ||
| 74 | $ret = $new->class ($args{CLASS}) or return ($ret) | ||
| 75 | if (defined ($args{CLASS})); | ||
| 76 | $ret = $new->ttl ($args{TTL}) or return ($ret) | ||
| 77 | if (defined ($args{TTL})); | ||
| 78 | |||
| 79 | $ret = $new->rtype ('MX') or return ($ret); | ||
| 80 | $ret = $new->mxpref ($args{MXPREF}) or return ($ret); | ||
| 81 | $ret = $new->rdata ($args{RDATA}) or return ($ret); | ||
| 82 | $ret = $new->label ($args{LABEL}) or return ($ret); | ||
| 83 | |||
| 84 | return ($new); | ||
| 85 | } | ||
| 86 | |||
| 87 | =item mxpref () | ||
| 88 | |||
| 89 | Arguments | ||
| 90 | mxpref # number | ||
| 91 | |||
| 92 | Object method. | ||
| 93 | Get/set the record's mxpref. If an argument is passed, the invocant's | ||
| 94 | mxpref is set and true returned, on success, an Err object otherwise. | ||
| 95 | If no argument is passed the invocant's mxpref is returned. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | # Object method. Get/Set MXPREF | ||
| 100 | sub mxpref | ||
| 101 | { | ||
| 102 | my ($self, $mxpref) = @_; | ||
| 103 | |||
| 104 | if (defined ($mxpref)) { | ||
| 105 | return (Unix::Conf->_err ('mxpref', "illegal MXPREF value `$mxpref'")) | ||
| 106 | if ($mxpref !~ /^\d+$/); | ||
| 107 | $self->{MXPREF} = $mxpref; | ||
| 108 | $self->dirty (1); | ||
| 109 | return (1); | ||
| 110 | } | ||
| 111 | return ( | ||
| 112 | defined ($self->{MXPREF}) ? $self->{MXPREF} : | ||
| 113 | Unix::Conf->_err ('mxpref', "MXPREF not defined") | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | |||
| 117 | 1; |