line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Bind8 Include |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright Karthik Krishnamurthy |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf::Include - Class for representing an 'include' |
8
|
|
|
|
|
|
|
statement in a Bind8 configuration file. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Objects of this class contain a Unix::Conf::Bind8::Conf object |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Unix::Conf::Bind8; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my ($conf, $include, $conf1, $ret); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$conf = Unix::Conf::Bind8->new_conf ( |
21
|
|
|
|
|
|
|
FILE => '/etc/named.conf', |
22
|
|
|
|
|
|
|
SECURE_OPEN => 1, |
23
|
|
|
|
|
|
|
) or $conf->die ("couldn't open `named.conf'"); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# Ways to get an include object |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$include = $conf->new_include ( |
30
|
|
|
|
|
|
|
FILE => 'slaves.conf', |
31
|
|
|
|
|
|
|
SECURE_OPEN => 0, |
32
|
|
|
|
|
|
|
) or $include->die ("couldn't create include object"); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# OR |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$include = $conf->get_include ('masters.conf') |
37
|
|
|
|
|
|
|
or $include->die ("couldn't get include object"); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# Operations that can be performed on an Include object |
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# get embedded conf object. |
44
|
|
|
|
|
|
|
$conf1 = $include->get_conf () |
45
|
|
|
|
|
|
|
or $conf1->die ("couldn't get conf"); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# set embedded conf object |
48
|
|
|
|
|
|
|
$conf1 = Unix::Conf::Bind8->new_conf ( |
49
|
|
|
|
|
|
|
FILE => '/etc/masters.conf', |
50
|
|
|
|
|
|
|
SECURE_OPEN => 0, |
51
|
|
|
|
|
|
|
) $conf1->die ("couldn't create `masters.conf'"); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$ret = $include->conf ($conf1) |
54
|
|
|
|
|
|
|
or $ret->die ("couldn't set conf"); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# delete include |
57
|
|
|
|
|
|
|
$ret = $include->delete () |
58
|
|
|
|
|
|
|
or $ret->die ("couldn't delete"); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# OR |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$ret = $conf->delete_include ('slaves.conf') |
63
|
|
|
|
|
|
|
or $ret->die ("couldn't delete"); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
package Unix::Conf::Bind8::Conf::Include; |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
10
|
|
50
|
use strict; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
450
|
|
72
|
10
|
|
|
10
|
|
50
|
use warnings; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
281
|
|
73
|
10
|
|
|
10
|
|
46
|
use Unix::Conf; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
177
|
|
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
10
|
|
50
|
use Unix::Conf::Bind8::Conf::Directive; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
933
|
|
76
|
|
|
|
|
|
|
our @ISA = qw (Unix::Conf::Bind8::Conf::Directive); |
77
|
|
|
|
|
|
|
|
78
|
10
|
|
|
10
|
|
63
|
use Unix::Conf::Bind8::Conf; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
1723
|
|
79
|
10
|
|
|
10
|
|
75
|
use Unix::Conf::Bind8::Conf::Lib; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
7321
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 4 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item new () |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Arguments |
86
|
|
|
|
|
|
|
FILE => 'path of the configuration file', |
87
|
|
|
|
|
|
|
SECURE_OPEN => 0/1, # default 1 (enabled) |
88
|
|
|
|
|
|
|
WHERE => 'FIRST'|'LAST'|'BEFORE'|'AFTER' |
89
|
|
|
|
|
|
|
WARG => Unix::Conf::Bind8::Conf::Directive subclass object |
90
|
|
|
|
|
|
|
# WARG is to be provided only in case WHERE eq 'BEFORE |
91
|
|
|
|
|
|
|
# or WHERE eq 'AFTER' |
92
|
|
|
|
|
|
|
PARENT => reference, # to the Conf object datastructure. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Class constructor. |
95
|
|
|
|
|
|
|
Creates a Unix::Conf::Bind8::Conf::Include object, with an embedded |
96
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf object, and returns it, on success, an Err |
97
|
|
|
|
|
|
|
object otherwise. Do not use this constructor directly. Use the |
98
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf::new_include () method instead. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub new |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
1
|
|
my $self = shift (); |
105
|
0
|
|
|
|
|
|
my %args = @_; |
106
|
0
|
|
|
|
|
|
my ($new, $ret, $new_conf); |
107
|
0
|
|
|
|
|
|
$new = bless ({}); |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
$args{PARENT} || return (Unix::Conf->_err ('new', "PARENT not specified")); |
110
|
0
|
0
|
|
|
|
|
$ret = $new->_parent ($args{PARENT}) or return ($ret); |
111
|
|
|
|
|
|
|
# Just make sure we were passed ROOT. It will however be set in the |
112
|
|
|
|
|
|
|
# Unix::Conf::Bind8::Conf->new () constructor |
113
|
0
|
0
|
|
|
|
|
$args{ROOT} || return (Unix::Conf->_err ('new', "ROOT not specified")); |
114
|
0
|
0
|
|
|
|
|
$new_conf = Unix::Conf::Bind8::Conf->new ( %args ) or return ($new_conf); |
115
|
0
|
0
|
|
|
|
|
$ret = $new->conf ($new_conf) or return ($ret); |
116
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_add_include ($new) or return ($ret); |
117
|
0
|
0
|
|
|
|
|
$args{WHERE} = 'LAST' unless ($args{WHERE}); |
118
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG}) |
119
|
|
|
|
|
|
|
or return ($ret); |
120
|
0
|
|
|
|
|
|
return ($new); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item name () |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the name of the include file. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub name |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
0
|
1
|
|
return (sprintf ("%s", $_[0]->conf ()->fh ())); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item conf () |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Arguments |
137
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf object, # optional |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Get/Set the embedded Unix::Conf::Bind8::Conf. If an argument is passed, the |
140
|
|
|
|
|
|
|
method tries to set the embedded object to the argument, and returns true |
141
|
|
|
|
|
|
|
if successful, an Err object otherwise. If the argument is not passed, returns |
142
|
|
|
|
|
|
|
the contained Unix::Conf::Bind8::Conf object. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub conf |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
0
|
1
|
|
my ($self, $conf) = @_; |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
if ($conf) { |
151
|
0
|
0
|
|
|
|
|
return (Unix::Conf->_err ('conf', "argument should be object of type Unix::Conf::Bind8::Conf")) |
152
|
|
|
|
|
|
|
unless (UNIVERSAL::isa ($conf, 'Unix::Conf::Bind8::Conf')); |
153
|
0
|
|
|
|
|
|
$self->{conf} = $conf; |
154
|
0
|
|
|
|
|
|
$self->dirty (1); |
155
|
0
|
|
|
|
|
|
return (1); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
return ( |
158
|
0
|
0
|
|
|
|
|
defined ($self->{conf}) ? $self->{conf} : Unix::Conf->_err ('conf', "conf not defined") |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub __root |
163
|
|
|
|
|
|
|
{ |
164
|
0
|
|
|
0
|
|
|
my ($self, $root) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
if ($root) { |
167
|
0
|
|
|
|
|
|
$self->{ROOT} = $root; |
168
|
0
|
|
|
|
|
|
return (1); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
return ( |
171
|
0
|
0
|
|
|
|
|
defined ($self->{ROOT}) ? $self->{ROOT} : |
172
|
|
|
|
|
|
|
Unix::Conf->_err ('__root', "ROOT not defined") |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub __render |
177
|
|
|
|
|
|
|
{ |
178
|
0
|
|
|
0
|
|
|
my $self = $_[0]; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $rendered = sprintf (qq (include "%s";), $self->conf ()->fh ()); |
181
|
0
|
|
|
|
|
|
return ($self->_rstring (\$rendered)); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
__END__ |