Bind8/Conf/Include.pm

filter: Statementstmt 40.8% 20 / 49 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 100% 3 / 3 totaltotal 32.5% 29 / 89 CC 14 SCAR 36.6
CC
14
Cov
27%
new
90.0
conf
20.0
__root
12.0
CRAP 39.0
« Bind8/DB/MX.pm ↑ Summary Bind8/Conf.pm »
1 # Bind8 Include
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 10 ▶use Unix::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 10 ▶use Unix::Conf::Bind8::Conf::Directive;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 10 our @ISA = qw (Unix::Conf::Bind8::Conf::Directive);
77  
78 10 ▶use Unix::Conf::Bind8::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 10 ▶use Unix::Conf::Bind8::Conf::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶{
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
104 0 my $self = shift ();
105 0 my %args = @_;
106 0 my ($new, $ret, $new_conf);
107 0 $new = bless ({});
108  
109 0 ▶ $args{PARENT} || return (Unix::Conf->_err ('new', "PARENT not specified"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"PARENT"} or return "Unix::Conf"->_err("new", "PARENT not specified") 0 0 0
110 0 ▶ $ret = $new->_parent ($args{PARENT}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->_parent($args{"PARENT"}) or return $ret 0 0 0
111 # Just make sure we were passed ROOT. It will however be set in the
112 # Unix::Conf::Bind8::Conf->new () constructor
113 0 ▶ $args{ROOT} || return (Unix::Conf->_err ('new', "ROOT not specified"));
Branch: 1 branch
BranchTrueFalseTotal
$args{"ROOT"} or return "Unix::Conf"->_err("new", "ROOT not specified") 0 0 0
114 0 ▶ $new_conf = Unix::Conf::Bind8::Conf->new ( %args ) or return ($new_conf);
Branch: 1 branch
BranchTrueFalseTotal
$new_conf = "Unix::Conf::Bind8::Conf"->new(%args) or return $new_conf 0 0 0
115 0 ▶ $ret = $new->conf ($new_conf) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->conf($new_conf) or return $ret 0 0 0
116 0 ▶ $ret = Unix::Conf::Bind8::Conf::_add_include ($new) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::_add_include($new) or return $ret 0 0 0
117 0 ▶ $args{WHERE} = 'LAST' unless ($args{WHERE});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"WHERE"} 0 0 0
118 $ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG})
119 0 ▶ or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::_insert_in_list($new, $args{"WHERE"}, $args{"WARG"}) or return $ret 0 0 0
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 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
131 0 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 0 ▶{
Subroutine conf: not called CC=4 SCAR=30.0
Pod documented
148 0 my ($self, $conf) = @_;
149  
150 0 ▶ if ($conf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf) 0 0 0
151 0 ▶ return (Unix::Conf->_err ('conf', "argument should be object of type Unix::Conf::Bind8::Conf"))
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($conf, "Unix::Conf::Bind8::Conf") 0 0 0
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 ▶ defined ($self->{conf}) ? $self->{conf} : Unix::Conf->_err ('conf', "conf not defined")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'conf'} ? : 0 0 0
159 );
160 }
161  
162 sub __root
163 0 ▶{
Subroutine __root: not called CC=3 SCAR=24.8
164 0 my ($self, $root) = @_;
165  
166 0 ▶ if ($root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root) 0 0 0
167 0 $self->{ROOT} = $root;
168 0 return (1);
169 }
170 return (
171 defined ($self->{ROOT}) ? $self->{ROOT} :
172 0 ▶ Unix::Conf->_err ('__root', "ROOT not defined")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'ROOT'} ? : 0 0 0
173 );
174 }
175  
176 sub __render
177 0 ▶{
Subroutine __render: not called CC=1 SCAR=6.9
178 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 10 1;
185 __END__
« Bind8/DB/MX.pm ↑ Summary Bind8/Conf.pm »