Bind8/Conf/Logging/Channel.pm

filter: Statementstmt 13.4% 25 / 186 Branchbran 0.0% 0 / 142 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 25.0% 6 / 24 Podpod 91.6% 11 / 12 totaltotal 10.5% 42 / 397 CC 78 SCAR 48.3
CC
78
Cov
7%
new
420.0
__render
182.0
name
72.0
CRAP 125.3
« Bind8/Conf/Acl.pm ↑ Summary Bind8/Conf/Logging.pm »
1 # Logging::Channel
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
4  
5 =head1 NAME
6  
7 Unix::Conf::Bind8::Conf::Logging::Channel - Class implementing the channel
8 subdirective of the logging directive
9  
10 =head1 SYNOPSIS
11  
12 use Unix::Conf::Bind8;
13 my ($conf, $channel, $ret);
14  
15 $conf = Unix::Conf::Bind8->new_conf (
16 FILE => '/etc/named.conf',
17 SECURE_OPEN => 1,
18 ) or $conf->die ("couldn't open `named.conf'");
19  
20 # get an existing logging object
21 $channel = $conf->get_logging ()->get_channel ('some_channel')
22 or $channel->die ("couldn't get channel `some_channel'");
23  
24 # assuming previous output was syslog change output to file
25 # and set severity to debug at level 3
26 $ret = $channel->output ('file')
27 or $ret->die ("couldn't set output to `file'");
28 $ret = $channel->file ('my.log')
29 or $ret->die ("couldn't set file to `my.log'");
30 $ret = $channel->severity ( { NAME => 'debug', LEVEL => 3 } )
31 or $ret->die ("couldn't set severity");
32  
33 # also enable print-severity
34 $ret = $channel->print_severity ('yes')
35 or $ret->die ("couldn't enable `print-severity'");
36  
37 # and delete the `print-category' channel directive
38 # not delete is not the same as disabling by setting
39 # print-severity to no
40 $ret = $channel->delete_print_severity ()
41 or $ret->die ("couldn't delete `print-severity'");
42  
43 =head1 DESCRIPTION
44  
45 =over 4
46  
47 =cut
48  
49 package Unix::Conf::Bind8::Conf::Logging::Channel;
50  
51 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 10 ▶use Unix::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 10 ▶use Unix::Conf::Bind8::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 10 ▶use Unix::Conf::Bind8::Conf::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 =item new ()
59  
60 Arguments
61 PARENT => ref to a Unix::Conf::Bind8::Conf::Logging object
62 NAME => 'channel-name',
63 OUTPUT => 'value', # syslog|file|null
64 FILE => {
65 PATH => 'file-name', # only if OUTPUT eq 'file'
66 VERSIONS => value, # 'unlimited' | NUMBER
67 SIZE => value, # 'unlimited' | 'default' | NUMBER
68 }
69 SYSLOG => 'facility-name',# only if OUTPUT eq 'syslog'
70 SEVERITY => 'severity-name',
71 'PRINT-TIME' => 'value', # yes|no
72 'PRINT-SEVERITY' => 'value', # yes|no
73 'PRINT-CATEGORY' => 'value', # yes|no
74  
75 Class constructor
76 Creates a new Unix::Conf::Bind8::Logging::Channel object, initializes it
77 and returns it on success, or an Err object on failure.
78  
79 =cut
80  
81 sub new
82 0 ▶{
Subroutine new: not called CC=20 SCAR=60.4
Pod documented
83 0 my $self = shift ();
84 0 my %args = @_;
85 0 my $new = bless ({ DIRTY => 0 });
86 0 my $ret;
87
88 return (Unix::Conf->_err ('new', "PARENT not specified"))
89 0 ▶ unless ($args{PARENT});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"PARENT"} 0 0 0
90 0 ▶ $ret = $new->_parent ($args{PARENT}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->_parent($args{"PARENT"}) or return $ret 0 0 0
91 return (Unix::Conf->_err ('new', "channel name not specified"))
92 0 ▶ unless ($args{NAME});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"NAME"} 0 0 0
93 0 ▶ $ret = $new->name ($args{NAME}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->name($args{"NAME"}) or return $ret 0 0 0
94  
95 0 ▶ if ($args{OUTPUT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"OUTPUT"}) 0 0 0
96 0 ▶ $ret = $new->output ($args{OUTPUT}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->output($args{"OUTPUT"}) or return $ret 0 0 0
97  
98 0 ▶ if ($args{OUTPUT} eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'OUTPUT'} eq 'file') { } 0 0 0
elsif ($args{'OUTPUT'} eq 'syslog') { } 0 0 0
99 return (Unix::Conf->_err ('output', "no arguments set for channel output 'file'"))
100 0 ▶ unless ($args{FILE});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"FILE"} 0 0 0
101 0 ▶ $ret = $new->file (%{$args{FILE}}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->file(%{$args{"FILE"};}) or return $ret 0 0 0
102 }
103 elsif ($args{OUTPUT} eq 'syslog') {
104 return (Unix::Conf->_err ('output', "facility not specified for channel output `syslog'"))
105 0 ▶ unless ($args{SYSLOG});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"SYSLOG"} 0 0 0
106 0 $new->syslog ($args{SYSLOG});
107 }
108 }
109  
110 0 $ret = $new->severity (%{$args{SEVERITY}}) or return ($ret)
111 0 ▶ if ($args{SEVERITY});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"SEVERITY"} 0 0 0
Condition0%0/5
$args{'SEVERITY'} && (($ret = $new->severity(%{$args{'SEVERITY'};})) || (return $ret))
!ll&&!rl&&r
000
$ret = $new->severity(%{$args{"SEVERITY"};}) or return $ret
l!l
00
MC/DC0%0/2
$args{'SEVERITY'} && (($ret = $new->severity(%{$args{'SEVERITY'};})) || (return $ret))
$args{'SEVERITY'} $ret = $new->severity(%{$args{"SEVERITY"};})
Truth table0%0/3
A && B
A= $args{'SEVERITY'}B= $ret = $new->severity(%{$args{"SEVERITY"};})
ABresult
0X0
100
111
112 $ret = $new->print_category ($args{'PRINT-CATEGORY'}) or return ($ret)
113 0 ▶ if ($args{'PRINT-CATEGORY'});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"PRINT-CATEGORY"} 0 0 0
Condition0%0/5
$args{'PRINT-CATEGORY'} && (($ret = $new->print_category($args{'PRINT-CATEGORY'})) || (return $ret))
!ll&&!rl&&r
000
$ret = $new->print_category($args{"PRINT-CATEGORY"}) or return $ret
l!l
00
MC/DC0%0/2
$args{'PRINT-CATEGORY'} && (($ret = $new->print_category($args{'PRINT-CATEGORY'})) || (return $ret))
$args{'PRINT-CATEGORY'} $ret = $new->print_category($args{"PRINT-CATEGORY"})
Truth table0%0/3
A && B
A= $args{'PRINT-CATEGORY'}B= $ret = $new->print_category($args{"PRINT-CATEGORY"})
ABresult
0X0
100
111
114 $ret = $new->print_severity ($args{'PRINT-SEVERITY'}) or return ($ret)
115 0 ▶ if ($args{'PRINT-SEVERITY'});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"PRINT-SEVERITY"} 0 0 0
Condition0%0/5
$args{'PRINT-SEVERITY'} && (($ret = $new->print_severity($args{'PRINT-SEVERITY'})) || (return $ret))
!ll&&!rl&&r
000
$ret = $new->print_severity($args{"PRINT-SEVERITY"}) or return $ret
l!l
00
MC/DC0%0/2
$args{'PRINT-SEVERITY'} && (($ret = $new->print_severity($args{'PRINT-SEVERITY'})) || (return $ret))
$args{'PRINT-SEVERITY'} $ret = $new->print_severity($args{"PRINT-SEVERITY"})
Truth table0%0/3
A && B
A= $args{'PRINT-SEVERITY'}B= $ret = $new->print_severity($args{"PRINT-SEVERITY"})
ABresult
0X0
100
111
116 $ret = $new->print_time ($args{'PRINT-TIME'}) or return ($ret)
117 0 ▶ if ($args{'PRINT-TIME'});
Branch: 1 branch
BranchTrueFalseTotal
if $args{"PRINT-TIME"} 0 0 0
Condition0%0/5
$args{'PRINT-TIME'} && (($ret = $new->print_time($args{'PRINT-TIME'})) || (return $ret))
!ll&&!rl&&r
000
$ret = $new->print_time($args{"PRINT-TIME"}) or return $ret
l!l
00
MC/DC0%0/2
$args{'PRINT-TIME'} && (($ret = $new->print_time($args{'PRINT-TIME'})) || (return $ret))
$args{'PRINT-TIME'} $ret = $new->print_time($args{"PRINT-TIME"})
Truth table0%0/3
A && B
A= $args{'PRINT-TIME'}B= $ret = $new->print_time($args{"PRINT-TIME"})
ABresult
0X0
100
111
118 0 return ($new);
119 }
120  
121 =item delete ()
122  
123 Arguments
124  
125 Object method.
126 Deletes the invocant.
127 Returns true on success, an Err object otherwise.
128  
129 =cut
130  
131 sub delete
132 0 ▶{
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
133 0 my $self = $_[0];
134 0 my $ret;
135  
136 return (Unix::Conf->_err ("delete", "channel still in use, cannot delete"))
137 0 ▶ if (keys (%{$self->{categories}}));
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"categories"};} 0 0 0
138  
139 0 ▶ $ret = Unix::Conf::Bind8::Conf::Logging::_del_channel ($self->_parent (), $self->name ())
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::Logging::_del_channel($self->_parent, $self->name) or return $ret 0 0 0
140 or return ($ret);
141 0 $self->__dirty (1);
142 0 return (1);
143 }
144  
145 =item name ()
146  
147 Arguments
148 'CHANNEL-NAME',
149  
150 Object method
151 Get/Set name attribute for the invoking object.
152 If called with an argument, sets channel name and returns true
153 on success, an Err object otherwise. Returns channel name if
154 invoked without an argument.
155  
156 =cut
157  
158 sub name
159 0 ▶{
Subroutine name: not called CC=8 SCAR=42.8
Pod documented
160 0 my ($self, $name) = @_;
161  
162 0 ▶ if (defined ($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 0 0
163 0 my $ret;
164 0 ▶ return (UNix::Conf->_err ('name', "illegal channel name `$name'"))
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
165 unless ($name);
166 0 ▶ return (Unix::Conf->_err ('name', "channel `$name' is predefined"))
Branch: 1 branch
BranchTrueFalseTotal
if Unix::Conf::Bind8::Conf::Logging::_is_predef_channel($name) 0 0 0
167 if (Unix::Conf::Bind8::Conf::Logging::_is_predef_channel ($name));
168 0 ▶ if ($self->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"name"}) 0 0 0
169 0 ▶ $ret = Unix::Conf::Bind8::Conf::Logging::_del_channel ($self)
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::Logging::_del_channel($self) or return $ret 0 0 0
170 or return ($ret);
171 }
172 0 $self->{name} = $name;
173 0 ▶ $ret = Unix::Conf::Bind8::Conf::Logging::_add_channel ($self)
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::Logging::_add_channel($self) or return $ret 0 0 0
174 or return ($ret);
175 0 $self->__dirty (1);
176 0 return (1);
177 }
178 return (
179 $self->{name} ? $self->{name} :
180 0 ▶ Unix::Conf->_err ('name', "channel `$name' not defined")
Branch: 1 branch
BranchTrueFalseTotal
$self->{'name'} ? : 0 0 0
181 );
182 }
183  
184 =item output ()
185  
186 Arguments
187 'OUTPUT', # syslog|file|null
188  
189 Object method.
190 Get/set attributes for the invoking object.
191 If called with an argument, tries to set the output to argument and
192 returns true if successful, an Err object otherwise. Returns the
193 currently set output if set, an Err object otherwise if called without
194 an argument.
195  
196 =cut
197  
198 sub output
199 0 ▶{
Subroutine output: not called CC=4 SCAR=30.0
Pod documented
200 0 my ($self, $output) = @_;
201  
202 0 ▶ if ($output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output) 0 0 0
203 0 ▶ return (Unix::Conf->_err ('output', "illegal channel output `$output'"))
Branch: 1 branch
BranchTrueFalseTotal
unless $output =~ /^(syslog|file|null)$/ 0 0 0
204 if ($output !~ /^(syslog|file|null)$/);
205 0 $self->{output} = $output;
206 0 $self->__dirty (1);
207 0 return (1);
208 }
209 return (
210 $self->{output} ? $self->{output} :
211 0 ▶ Unix::Conf->_err ('output', "channel output not defined")
Branch: 1 branch
BranchTrueFalseTotal
$self->{'output'} ? : 0 0 0
212 );
213 }
214  
215 =item file ()
216  
217 Arguments
218 PATH => 'path_name',
219 VERSIONS => versions_allowed, # 'unlimited' | NUMBER
220 SIZE => size_spec, # 'unlimited' | 'default' | NUMBER
221  
222 Object method.
223 Get/set file attributes for the invoking object.
224 If argument is passed, the method tries to set the file parameters and
225 returns true if successful, an Err object otherwise. Returns a hash ref
226 containing information in the same format as the argument, if defined,
227 an Err object otherwise, if called without an argument.
228  
229 =cut
230  
231 sub file
232 0 ▶{
Subroutine file: not called CC=7 SCAR=40.3
Pod documented
233 0 my $self = shift ();
234 0 my %args = @_;
235  
236 0 ▶ if ($args{PATH}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"PATH"}) 0 0 0
237 0 $self->{path} = $args{PATH};
238 0 __valid_string ($self->{path});
239 0 ▶ if (defined ($args{VERSIONS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"VERSIONS"}) 0 0 0
240 return (Unix::Conf->_err ('file', "illegal versions argument `$args{VERSIONS}'"))
241 0 ▶ if ($args{VERSIONS} !~ /^(\d+|unlimited)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"VERSIONS"} =~ /^(\d+|unlimited)$/ 0 0 0
242 0 $self->{versions} = $args{VERSIONS};
243 }
244 0 ▶ if (defined ($args{SIZE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"SIZE"}) 0 0 0
245 return (Unix::Conf->_err ('file', "illegal size argument `$args{SIZE}'"))
246 0 ▶ unless (__valid_sizespec ($args{SIZE}));
Branch: 1 branch
BranchTrueFalseTotal
unless &__valid_sizespec($args{"SIZE"}) 0 0 0
247 0 $self->{size} = $args{SIZE};
248 }
249 0 $self->__dirty (1);
250 0 return (1);
251 }
252 return (Unix::Conf->_err ('file', "file path not defined"))
253 0 ▶ unless ($self->{path});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"path"} 0 0 0
254 0 return ({ PATH => $self->{path}, VERSIONS => $self->{versions}, SIZE => $self->{size} });
255 }
256  
257 =item syslog ()
258  
259 Arguments
260 facility, # kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron
261 # |authpriv|ftp|local0|local1|local2|local3|local4|local5
262 # local6|local7
263 Object method.
264 Get/Set the syslog attribute of the invoking channel object.
265 If called with an argument, the method tries to set the facility and
266 returns true if successful, an Err object otherwise. Returns defined
267 facility if called without an argument, an Err object otherwise.
268  
269 =cut
270  
271 sub syslog
272 0 ▶{
Subroutine syslog: not called CC=4 SCAR=30.0
Pod documented
273 0 my ($self, $syslog) = @_;
274  
275 0 ▶ if ($syslog) {
Branch: 1 branch
BranchTrueFalseTotal
if ($syslog) 0 0 0
276 0 ▶ return (Unix::Conf->_err ('syslog', "illegal syslog facility"))
Branch: 1 branch
BranchTrueFalseTotal
unless $syslog =~ /^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local[0-7])$/ 0 0 0
277 if ($syslog !~ /^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local[0-7])$/);
278 0 $self->{syslog} = $syslog;
279 0 $self->__dirty (1);
280 0 return (1);
281 }
282 return (
283 0 ▶ $self->{syslog} ? $self->{syslog} : Unix::Conf->_err ('syslog', "syslog facility not defined")
Branch: 1 branch
BranchTrueFalseTotal
$self->{'syslog'} ? : 0 0 0
284 );
285 }
286  
287 =item severity ()
288  
289 Arguments
290 NAME => severity, # critical|error|warning|notice|info
291 # |debug|dynamic
292 LEVEL => number, # debug level. to be specified only if
293 # severity is debug.
294  
295 Object method
296 Get/Set the severity attribute of the invoking object.
297 If argument is specified the method tries to set the severity and
298 returns true on success, an Err object on failure. Returns defined
299 severity if called without an argument, an Err object otherwise.
300  
301 =cut
302  
303 sub severity
304 0 ▶{
Subroutine severity: not called CC=6 SCAR=37.4
Pod documented
305 0 my $self = shift ();
306 0 my %args = @_;
307  
308 0 ▶ if ($args{NAME}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"NAME"}) 0 0 0
309 return (Unix::Conf->_err ('severity', "illegal severity `$args{NAME}'"))
310 0 ▶ if ($args{NAME} !~ /^(critical|error|warning|notice|info|debug|dynamic)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"NAME"} =~ /^(critical|error|warning|notice|info|debug|dynamic)$/ 0 0 0
311 return (Unix::Conf->_err ('severity', "LEVEL can be set only for severity `debug'"))
312 0 ▶ if ($args{LEVEL} && $args{NAME} ne 'debug');
Branch: 1 branch
BranchTrueFalseTotal
if $args{"LEVEL"} and $args{"NAME"} ne "debug" 0 0 0
Condition0%0/3
$args{"LEVEL"} and $args{"NAME"} ne "debug"
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"LEVEL"} and $args{"NAME"} ne "debug"
$args{"LEVEL"} $args{"NAME"} ne "debug"
Truth table0%0/3
A and B
A= $args{"LEVEL"}B= $args{"NAME"} ne "debug"
ABresult
0X0
100
111
313 0 $self->{severity} = $args{NAME};
314 0 $self->{level} = $args{LEVEL};
315 0 $self->__dirty (1);
316 0 return (1);
317 }
318 return (Unix::Conf->_err ('severity', "severity not defined"))
319 0 ▶ unless ($self->{severity});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"severity"} 0 0 0
320 0 return (return ({ NAME => $self->{severity}, LEVEL => $self->{level}}));
321 }
322  
323 =item print_time ()
324  
325 Arguments
326 yes_no,
327  
328 Object method.
329 Get/Set attribute of the invoking Channel object.
330 If argument is passed, this method tries to set the value and returns
331 true on success, an Err object on failure. Returns defined value of
332 'print-time' if defined, an Err object otherwise, if called without an
333 argument.
334  
335 =cut
336  
337 sub print_time
338 0 ▶{
Subroutine print_time: not called CC=4 SCAR=30.0
Pod documented
339 0 my ($self, $print) = @_;
340  
341 0 ▶ if ($print) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print) 0 0 0
342 0 ▶ return (Unix::Conf->_err ('print_time', "illegal argument `$print'"))
Branch: 1 branch
BranchTrueFalseTotal
unless &__valid_yesno($print) 0 0 0
343 unless (__valid_yesno ($print));
344 0 $self->{'print-time'} = $print;
345 0 $self->__dirty (1);
346 0 return (1);
347 }
348 return (
349 0 ▶ $self->{'print-time'} ? $self->{'print-time'} :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'print-time'} ? : 0 0 0
350 Unix::Conf->_err ('print_time', "print-time not defined")
351 );
352 }
353  
354 =item print_category ()
355  
356 Arguments
357 yes_no,
358  
359 Object method.
360 Get/Set attribute of the invoking Channel object.
361 If argument is passed, this method tries to set the value and returns
362 true on success, an Err object on failure. Returns defined value of
363 'print-category' if defined, an Err object otherwise, if called without
364 an argument.
365  
366 =cut
367  
368 sub print_category
369 0 ▶{
Subroutine print_category: not called CC=4 SCAR=30.0
Pod documented
370 0 my ($self, $print) = @_;
371  
372 0 ▶ if ($print) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print) 0 0 0
373 0 ▶ return (Unix::Conf->_err ('print_category', "illegal argument `$print'"))
Branch: 1 branch
BranchTrueFalseTotal
unless &__valid_yesno($print) 0 0 0
374 unless (__valid_yesno ($print));
375 0 $self->{'print-category'} = $print;
376 0 $self->__dirty (1);
377 0 return (1);
378 }
379 return (
380 0 ▶ $self->{'print-category'} ? $self->{'print-category'} :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'print-category'} ? : 0 0 0
381 Unix::Conf->_err ('print_category', "print-category not defined")
382 );
383 }
384  
385 =item print_severity ()
386  
387 Arguments
388 yes_no,
389  
390 Object method.
391 Get/Set attribute of the invoking Channel object.
392 If argument is passed, this method tries to set the value and returns
393 true on success, an Err object on failure. Returns defined value of
394 'print-severity' if defined, an Err object otherwise, if called
395 without an argument.
396  
397 =cut
398  
399 sub print_severity
400 0 ▶{
Subroutine print_severity: not called CC=4 SCAR=30.0
Pod documented
401 0 my ($self, $print) = @_;
402  
403 0 ▶ if ($print) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print) 0 0 0
404 0 ▶ return (Unix::Conf->_err ('print_severity', "illegal argument `$print'"))
Branch: 1 branch
BranchTrueFalseTotal
unless &__valid_yesno($print) 0 0 0
405 unless (__valid_yesno ($print));
406 0 $self->{'print-severity'} = $print;
407 0 $self->__dirty (1);
408 0 return (1);
409 }
410 return (
411 0 ▶ $self->{'print-severity'} ? $self->{'print-severity'} :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'print-severity'} ? : 0 0 0
412 Unix::Conf->_err ('print_severity', "print-severity not defined")
413 );
414 }
415  
416 10 my %Channel_Directives = (
417 'output' => 1,
418 'severity' => 1,
419 'print-category' => 1,
420 'print-severity' => 1,
421 'print-time' => 1,
422 );
423  
424 =cut delete_channeldir ()
425  
426 Arguments
427 'directive-name',
428  
429 Tries to delete the directive specified by argument if defined.
430 Returns true on success, an Err object otherwise.
431  
432 =cut
433  
434 sub delete_channeldir
435 0 ▶{
Subroutine delete_channeldir: not called CC=3 SCAR=24.8
Pod undocumented
436 0 my ($self, $directive) = @_;
437  
438 return (Unix::Conf->_err ('delete_channeldir', "illegal channel directive `$directive'"))
439 0 ▶ unless ($Channel_Directives{$directive});
Branch: 1 branch
BranchTrueFalseTotal
unless $Channel_Directives{$directive} 0 0 0
440 return (Unix::Conf->_err ("delete_channeldir", "channel directive `$directive' not defined"))
441 0 ▶ unless ($self->{$directive});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$directive} 0 0 0
442 0 undef ($self->{$directive});
443 0 $self->__dirty (1);
444 0 return (1);
445 }
446  
447 =item delete_output ()
448  
449 =item delete_severity ()
450  
451 =item delete_print_time ()
452  
453 =item delete_print_category ()
454  
455 =item delete_print_severity ()
456  
457 Deletes the relevant directives and returns true, if defined, an Err object
458 otherwise.
459  
460 =cut
461  
462 10 for my $directive (keys (%Channel_Directives)) {
463 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
464 50 my $meth = $directive;
465 50 $meth =~ s/-/_/g;
466 50 ▶ *{"delete_$meth"} = sub {
Subroutine __ANON__: not called CC=2 SCAR=15.4
467 0 my $self = $_[0];
468 return (Unix::Conf->_err ("delete_$meth", "channel directive `$directive' not defined"))
469 0 ▶ unless ($self->{$directive});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$directive} 0 0 0
470 0 undef ($self->{$directive});
471 0 $self->__dirty (1);
472 0 return (1);
473 50 };
474 }
475  
476 =item categories ()
477  
478 Object method.
479 Returns the categories that have defined this channel. In scalar context
480 returns the number of categories, returns a list of category names in list
481 context.
482  
483 =cut
484  
485 sub categories ()
486 0 ▶{
Subroutine categories: not called CC=1 SCAR=6.9
Pod documented
487 0 return (keys (%{$_[0]->{categories}}));
488 }
489  
490 sub _add_category ()
491 0 ▶{
Subroutine _add_category: not called CC=2 SCAR=17.9
492 0 my $self = shift ();
493  
494 0 ▶ return (Unix::Conf->_err ("_add_category", "categories to be added not passed"))
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
495 unless (@_);
496
497 0 @{$self->{categories}}{@_} = (1) x @_;
498 0 return (1);
499 }
500  
501 sub _delete_category ()
502 0 ▶{
Subroutine _delete_category: not called CC=4 SCAR=30.0
503 0 my $self = shift ();
504  
505 0 ▶ return (Unix::Conf->_err ("_delete_category", "categories to be deleted not passed"))
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
506 unless (@_);
507  
508 0 for (@_) {
509 return (
510 Unix::Conf->_err (
511 "_delete_category",
512 sprintf ("category `$_' does not use %s", $self->name ())
513 )
514 0 ▶ ) unless ($self->{categories}{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"categories"}{$_} 0 0 0
515 }
516 0 delete (@{$self->{categories}}{@_});
517 0 return (1);
518 }
519  
520 sub __render
521 0 ▶{
Subroutine __render: not called CC=13 SCAR=52.0
522 0 my $self = $_[0];
523 0 my ($tmp, $rendered);
524  
525 0 $rendered = sprintf ("\tchannel %s {\n", $self->name ());
526 0 ▶ if (($tmp = $self->output ()) eq 'file') {
Branch: 3 branches
BranchTrueFalseTotal
if (($tmp = $self->output) eq 'file') { } 0 0 0
elsif ($tmp eq 'syslog') { } 0 0 0
elsif ($tmp eq 'null') { } 0 0 0
527 0 my $file;
528 0 ▶ $file = $self->file () or return ($file);
Branch: 1 branch
BranchTrueFalseTotal
$file = $self->file or return $file 0 0 0
529 0 $rendered .= qq (\t\tfile "$file->{PATH}");
530 $rendered .= " versions $file->{VERSIONS}"
531 0 ▶ if ($file->{VERSIONS});
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"VERSIONS"} 0 0 0
532 $rendered .= " size $file->{SIZE}"
533 0 ▶ if ($file->{SIZE});
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"SIZE"} 0 0 0
534 0 $rendered .= ";\n";
535 }
536 elsif ($tmp eq 'syslog') {
537 # while the syntax in the man page indicates that
538 # a syslog facility is mandatory, the sample named.conf
539 # file that comes with named-8.2.3 has just such an
540 # example
541 0 my $facility;
542 0 $rendered .= "\t\tsyslog";
543 0 ▶ $rendered .= " $facility"
Branch: 1 branch
BranchTrueFalseTotal
if $facility = $self->syslog 0 0 0
544 if (($facility = $self->syslog ()));
545 0 $rendered .= ";\n";
546 }
547 elsif ($tmp eq 'null') {
548 0 $rendered .= "\t\tnull;\n";
549 }
550  
551 0 ▶ if (($tmp = $self->severity ())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp = $self->severity) 0 0 0
552 0 $rendered .= "\t\tseverity $tmp->{NAME}";
553 $rendered .= " $tmp->{LEVEL}"
554 0 ▶ if ($tmp->{LEVEL});
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->{"LEVEL"} 0 0 0
555 0 $rendered .= ";\n";
556 }
557 0 ▶ $rendered .= "\t\tprint-category $tmp;\n"
Branch: 1 branch
BranchTrueFalseTotal
if $tmp = $self->print_category 0 0 0
558 if (($tmp = $self->print_category ()));
559 0 ▶ $rendered .= "\t\tprint-severity $tmp;\n"
Branch: 1 branch
BranchTrueFalseTotal
if $tmp = $self->print_severity 0 0 0
560 if (($tmp = $self->print_severity ()));
561 0 ▶ $rendered .= "\t\tprint-time $tmp;\n"
Branch: 1 branch
BranchTrueFalseTotal
if $tmp = $self->print_time 0 0 0
562 if (($tmp = $self->print_time ()));
563 0 $rendered .= "\t};\n";
564 0 return ($rendered);
565 }
566  
567 sub __dirty
568 0 ▶{
Subroutine __dirty: not called CC=2 SCAR=17.9
569 0 ▶ if (defined ($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
570 0 $_[0]->{PARENT}->dirty ($_[1]);
571 0 return (1);
572 }
573 0 return ($_[0]->{PARENT}->dirty ());
574 }
575  
576 # Stores the Logging object.
577 sub _parent
578 0 ▶{
Subroutine _parent: not called CC=4 SCAR=30.0
579 0 my ($self, $parent) = @_;
580  
581 0 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 0 0 0
582 # Do not allow resetting the PARENT ref. We don't use
583 # PARENT for anything else except calling the dirty method.
584 return (Unix::Conf->_err ('__parent', "PARENT already defined. Cannot reset"))
585 0 ▶ if ($self->{PARENT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PARENT"} 0 0 0
586 0 $self->{PARENT} = $parent;
587 0 return (1);
588 }
589 return (
590 $self->{PARENT} ? $self->{PARENT} :
591 0 ▶ Unix::Conf->_err ('_parent', "PARENT not defined")
Branch: 1 branch
BranchTrueFalseTotal
$self->{'PARENT'} ? : 0 0 0
592 );
593 }
594  
595 10 1;
596 __END__
« Bind8/Conf/Acl.pm ↑ Summary Bind8/Conf/Logging.pm »