line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Base class for all directives. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright Karthik Krishnamurthy |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf::Directive - Base class for all classes representing |
8
|
|
|
|
|
|
|
various directives in a Bind8 configuration file. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This class is also used directly for representing dummy directives, i.e. ones |
13
|
|
|
|
|
|
|
that represent comments, whitespace etc.. between two directives. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Unix::Conf::Bind8::Conf::Directive; |
18
|
|
|
|
|
|
|
|
19
|
10
|
|
|
10
|
|
56
|
use strict; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
407
|
|
20
|
10
|
|
|
10
|
|
48
|
use warnings; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
214
|
|
21
|
|
|
|
|
|
|
|
22
|
10
|
|
|
10
|
|
52
|
use Unix::Conf; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
2962
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over 4 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item new () |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Class method. |
29
|
|
|
|
|
|
|
Returns a Unix::Conf::Bind8::Conf::Directive object. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
1
|
|
my $class = shift (); |
36
|
0
|
|
|
|
|
|
my %args = @_; |
37
|
0
|
|
|
|
|
|
my ($new, $ret); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
return (Unix::Conf->_err ('new', "not an object constructor")) |
40
|
|
|
|
|
|
|
if (ref ($class)); |
41
|
0
|
0
|
|
|
|
|
$args{PARENT} || return (Unix::Conf->_err ('new', "PARENT not specified")); |
42
|
0
|
|
|
|
|
|
$new = bless ({}, $class); |
43
|
0
|
0
|
|
|
|
|
$ret = $new->_parent ($args{PARENT}) or return ($ret); |
44
|
0
|
0
|
|
|
|
|
$args{WHERE} = 'LAST' unless ($args{WHERE}); |
45
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG}) |
46
|
|
|
|
|
|
|
or return ($ret); |
47
|
0
|
|
|
|
|
|
return ($new); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub DESTROY |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
|
|
my $self = $_[0]; |
53
|
|
|
|
|
|
|
# all directive types are hash |
54
|
|
|
|
|
|
|
# delete hash |
55
|
0
|
|
|
|
|
|
undef (%$self); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item dirty () |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Arguments |
61
|
|
|
|
|
|
|
0/1, # optional |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Object method. |
64
|
|
|
|
|
|
|
If argument is passed its value is set as the dirty flag. 0 for false, 1 for |
65
|
|
|
|
|
|
|
true. Sets the object as dirty. If argument is not passed returns the value |
66
|
|
|
|
|
|
|
of the dirty flag, which can be evaluted in a boolean context. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub dirty |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
0
|
|
0
|
1
|
|
if (defined ($_[1])) { |
73
|
0
|
|
|
|
|
|
$_[0]->{DIRTY} = $_[1]; |
74
|
0
|
|
|
|
|
|
$_[0]->{PARENT}{DIRTY} = $_[1]; |
75
|
0
|
|
|
|
|
|
return (1) |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return ($_[0]->{DIRTY}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item delete () |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Object method. |
83
|
|
|
|
|
|
|
Deletes the directive. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub delete |
88
|
|
|
|
|
|
|
{ |
89
|
10
|
|
|
10
|
|
51
|
no strict 'refs'; |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
4312
|
|
90
|
0
|
|
|
0
|
1
|
|
my $self = $_[0]; |
91
|
0
|
|
|
|
|
|
my $ret; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Get the class of the invocant |
94
|
0
|
|
|
|
|
|
my $type = ref ($self); |
95
|
0
|
|
|
|
|
|
$type =~ s/^.+::(.+)$/$1/; |
96
|
0
|
|
|
|
|
|
$type = lc ($type); |
97
|
0
|
|
|
|
|
|
my $meth = "Unix::Conf::Bind8::Conf::_del_$type"; |
98
|
0
|
0
|
|
|
|
|
$ret = &$meth ($self) or return ($ret); |
99
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_delete_from_list ($self) |
100
|
|
|
|
|
|
|
or return ($ret); |
101
|
0
|
|
|
|
|
|
$self->dirty (1); |
102
|
0
|
|
|
|
|
|
return (1); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _parent |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
0
|
|
|
my ($self, $parent) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if ($parent) { |
110
|
|
|
|
|
|
|
# do not allow resetting as PARENT is used to register/update ouself in |
111
|
|
|
|
|
|
|
# the PARENT specific hashes and doubly linked list. |
112
|
0
|
0
|
|
|
|
|
return (Unix::Conf->_err ('_parent', "PARENT already defined. Cannot reset")) |
113
|
|
|
|
|
|
|
if ($self->{PARENT}); |
114
|
0
|
|
|
|
|
|
$self->{PARENT} = $parent; |
115
|
0
|
|
|
|
|
|
return (1); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
return ( |
118
|
0
|
0
|
|
|
|
|
defined ($self->{PARENT}) ? $self->{PARENT} : |
119
|
|
|
|
|
|
|
Unix::Conf->_err ('_parent', "`PARENT' not defined") |
120
|
|
|
|
|
|
|
) |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# get/set method. |
124
|
|
|
|
|
|
|
# if argument passed it sets the rendered string for the directive. else |
125
|
|
|
|
|
|
|
# returns the directive rendered as a string. |
126
|
|
|
|
|
|
|
sub _rstring |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
0
|
|
|
my ($self, $string, $arg) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if (defined ($string)) { |
131
|
0
|
0
|
|
|
|
|
$self->{RENDERED} = ref ($string) ? $string : \$string; |
132
|
0
|
|
|
|
|
|
$self->dirty (0); |
133
|
0
|
|
|
|
|
|
return (1); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
# make sure we render before returning IF dirty |
136
|
0
|
0
|
|
|
|
|
if ($self->dirty ()) { |
137
|
0
|
|
|
|
|
|
$self->__render ($arg); |
138
|
0
|
|
|
|
|
|
$self->dirty (0); |
139
|
|
|
|
|
|
|
} |
140
|
0
|
|
|
|
|
|
return ($self->{RENDERED}); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# set method. |
144
|
|
|
|
|
|
|
sub _tws |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
0
|
|
|
my ($self, $string) = @_; |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
if (defined ($string)) { |
149
|
0
|
0
|
|
|
|
|
$self->{TWS} = ref ($string) ? $string : \$string; |
150
|
0
|
|
|
|
|
|
return (1); |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
return ($self->{TWS}); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
__END__ |