Bind8/DB/SOA.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 108 CC 10 SCAR 23.1
CC
10
Cov
0%
serial
20.0
new
12.0
auth_ns
12.0
CRAP 10.1
1 # Bind8 SOA record handling
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
4  
5 =head1 NAME
6  
7 Unix::Conf::Bind8::DB::A - Class representing A 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::SOA;
24  
25 use strict;
26 use warnings;
27  
28 use Unix::Conf;
29 use Unix::Conf::Bind8::DB;
30 use Unix::Conf::Bind8::DB::Lib;
31 use Unix::Conf::Bind8::DB::Record;
32  
33 our @ISA = qw (Unix::Conf::Bind8::DB::Record);
34  
35 =item new ()
36  
37 Arguments
38 LABEL => 'string',
39 CLASS => 'string', # 'IN'|'HS'|'CHAOS'
40 TTL => 'string'|number,
41 AUTH_NS => 'nameserver',
42 MAIL_ADDR => 'rp',
43 SERIAL => zone_serial_no # number
44 REFRESH => refresh,
45 RETRY => retry,
46 EXPIRE => expire,
47 MIN_TTL => min_ttl,
48 PARENT => reference, # to the DB object datastructure
49  
50 Class constructor.
51 Creates a new Unix::Conf::Bind8::DB::* object and returns it
52 if successful, an Err object otherwise. Do not use this constructor
53 directly. Use the Unix::Conf::Bind8::DB::new_* equivalent instead.
54  
55 =cut
56  
57 # class constructor.
58 # Arguments: hash
59 # PARENT =>
60 # CLASS =>
61 # TTL =>
62 # AUTH_NS =>
63 # MAIL_ADDR =>
64 # SERIAL =>
65 # REFRESH =>
66 # RETRY =>
67 # EXPIRE =>
68 # MIN_TTL =>
69 #
70 sub new
71 {
72 my $class = shift ();
73 my %args = @_;
74 my $new = bless ({}, $class);
75 my $ret;
76  
77 return (Unix::Conf->_errr ('new', "`PARENT' not specified"))
78 unless (defined ($args{PARENT}));
79 $ret = $new->_parent ($args{PARENT}) or return ($ret);
80 # check all arguments in the loop and call appropriate methods to set them
81 for my $key qw (AUTH_NS MAIL_ADDR SERIAL REFRESH RETRY EXPIRE MIN_TTL RTYPE) {
82 return (Unix::Conf->_err ('new', "`$key' not specified"))
83 unless (defined ($args{$key}));
84 my $meth = lc ($key);
85 $ret = $new->$meth ($args{$key}) or return ($ret);
86 }
87 return ($new);
88 }
89  
90 =item auth_ns ()
91  
92 Arguments
93 'auth_ns'
94  
95 Object method.
96 Get/set the record's auth_ns. If an argument is passed, the invocant's
97 auth_ns is set and true returned, on success, an Err object otherwise.
98 If no argument is passed the invocant's auth_ns is returned.
99  
100 =cut
101  
102 sub auth_ns
103 {
104 my ($self, $auth_ns) = @_;
105  
106 if (defined ($auth_ns)) {
107 $self->{AUTH_NS} = $auth_ns;
108 $self->dirty (1);
109 return (1);
110 }
111 return (
112 defined ($self->{AUTH_NS}) ? $self->{AUTH_NS} :
113 Unix::Conf->_err ('auth_ns', "AUTH_NS not defined")
114 );
115 }
116  
117 =item mail_addr ()
118  
119 Arguments
120 'mail_addr'
121  
122 Object method.
123 Get/set the record's mail_addr. If an argument is passed, the invocant's
124 mail_addr is set and true returned, on success, an Err object otherwise.
125 If no argument is passed the invocant's mail_addr is returned.
126  
127 =cut
128  
129 sub mail_addr
130 {
131 my ($self, $mail_addr) = @_;
132  
133 if (defined ($mail_addr)) {
134 $self->{MAIL_ADDR} = $mail_addr;
135 $self->dirty (1);
136 return (1);
137 }
138 return (
139 defined ($self->{MAIL_ADDR}) ? $self->{MAIL_ADDR} :
140 Unix::Conf->_err ('mail_addr', "MAIL_ADDR not defined")
141 );
142 }
143  
144 =item serial ()
145  
146 Arguments
147 'serial'
148  
149 Object method.
150 Get/set the record's serial. If an argument is passed, the invocant's
151 serial is set and true returned, on success, an Err object otherwise.
152 If no argument is passed the invocant's serial is returned.
153  
154 =cut
155  
156 sub serial
157 {
158 my ($self, $serial) = @_;
159  
160 if (defined ($serial)) {
161 return (Unix::Conf->_err ('serial', "illegal SERIAL value `$serial'"))
162 unless ($serial =~ /^\d+$/);
163 $self->{SERIAL} = $serial;
164 $self->dirty (1);
165 return (1);
166 }
167 return (
168 defined ($self->{SERIAL}) ? $self->{SERIAL} :
169 Unix::Conf->_err ('mail_addr', "SERIAL not defined")
170 );
171 }
172  
173 =item refresh ()
174  
175 Arguments
176 'refresh'
177  
178 Object method.
179 Get/set the record's refresh. If an argument is passed, the invocant's
180 refresh is set and true returned, on success, an Err object otherwise.
181 If no argument is passed the invocant's refresh is returned.
182  
183 =cut
184  
185 =item retry ()
186  
187 Arguments
188 'retry'
189  
190 Object method.
191 Get/set the record's retry. If an argument is passed, the invocant's
192 retry is set and true returned, on success, an Err object otherwise.
193 If no argument is passed the invocant's retry is returned.
194  
195 =cut
196  
197 =item expire ()
198  
199 Arguments
200 'expire'
201  
202 Object method.
203 Get/set the record's expire. If an argument is passed, the invocant's
204 expire is set and true returned, on success, an Err object otherwise.
205 If no argument is passed the invocant's expire is returned.
206  
207 =cut
208  
209 =item min_ttl ()
210  
211 Arguments
212 'min_ttl'
213  
214 Object method.
215 Get/set the record's min_ttl. If an argument is passed, the invocant's
216 min_ttl is set and true returned, on success, an Err object otherwise.
217 If no argument is passed the invocant's min_ttl is returned.
218  
219 =cut
220  
221 for my $meth qw (refresh retry expire min_ttl) {
222 no strict 'refs';
223  
224 *$meth = sub {
225 my ($self, $arg) = @_;
226 my $key = uc ($meth);
227 if (defined ($arg)) {
228 return (Unix::Conf->_err ("$meth", "illegal $key value `$arg'"))
229 unless (__is_validttl ($arg));
230 $self->{$key} = $arg;
231 $self->dirty (1);
232 return (1);
233 }
234 return (
235 defined ($self->{$key}) ? $self->{$key} :
236 Unix::Conf->_err ("$meth", "`$key' not defined")
237 )
238 };
239 }
240  
241 1;