Bind8/Conf/Directive.pm

filter: Statementstmt 21.6% 13 / 60 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 100% 3 / 3 totaltotal 18.8% 20 / 106 CC 17 SCAR 29.0
CC
17
Cov
14%
new
42.0
_parent
20.0
_rstring
20.0
CRAP 18.2
« Bind8/DB/Record.pm ↑ Summary Bind8/DB/A.pm »
1 # Base class for all directives.
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 10 ▶use Unix::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶{
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
35 0 my $class = shift ();
36 0 my %args = @_;
37 0 my ($new, $ret);
38  
39 0 ▶ return (Unix::Conf->_err ('new', "not an object constructor"))
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
40 if (ref ($class));
41 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
42 0 $new = bless ({}, $class);
43 0 ▶ $ret = $new->_parent ($args{PARENT}) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = $new->_parent($args{"PARENT"}) or return $ret 0 0 0
44 0 ▶ $args{WHERE} = 'LAST' unless ($args{WHERE});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"WHERE"} 0 0 0
45 $ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG})
46 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
47 0 return ($new);
48 }
49  
50 sub DESTROY
51 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
52 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 0 ▶{
Subroutine dirty: not called CC=2 SCAR=17.9
Pod documented
72 0 ▶ if (defined ($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
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 0 ▶{
Subroutine delete: not called CC=3 SCAR=20.8
Pod documented
89 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 0 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 ▶ $ret = &$meth ($self) or return ($ret);
Branch: 1 branch
BranchTrueFalseTotal
$ret = &$meth($self) or return $ret 0 0 0
99 0 ▶ $ret = Unix::Conf::Bind8::Conf::_delete_from_list ($self)
Branch: 1 branch
BranchTrueFalseTotal
$ret = Unix::Conf::Bind8::Conf::_delete_from_list($self) or return $ret 0 0 0
100 or return ($ret);
101 0 $self->dirty (1);
102 0 return (1);
103 }
104  
105 sub _parent
106 0 ▶{
Subroutine _parent: not called CC=4 SCAR=30.0
107 0 my ($self, $parent) = @_;
108  
109 0 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 0 0 0
110 # do not allow resetting as PARENT is used to register/update ouself in
111 # the PARENT specific hashes and doubly linked list.
112 return (Unix::Conf->_err ('_parent', "PARENT already defined. Cannot reset"))
113 0 ▶ if ($self->{PARENT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PARENT"} 0 0 0
114 0 $self->{PARENT} = $parent;
115 0 return (1);
116 }
117 return (
118 defined ($self->{PARENT}) ? $self->{PARENT} :
119 0 ▶ Unix::Conf->_err ('_parent', "`PARENT' not defined")
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'PARENT'} ? : 0 0 0
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 0 ▶{
Subroutine _rstring: not called CC=4 SCAR=30.0
128 0 my ($self, $string, $arg) = @_;
129  
130 0 ▶ if (defined ($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 0 0 0
131 0 ▶ $self->{RENDERED} = ref ($string) ? $string : \$string;
Branch: 1 branch
BranchTrueFalseTotal
ref $string ? : 0 0 0
132 0 $self->dirty (0);
133 0 return (1);
134 }
135 # make sure we render before returning IF dirty
136 0 ▶ if ($self->dirty ()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dirty) 0 0 0
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 0 ▶{
Subroutine _tws: not called CC=3 SCAR=24.8
146 0 my ($self, $string) = @_;
147  
148 0 ▶ if (defined ($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 0 0 0
149 0 ▶ $self->{TWS} = ref ($string) ? $string : \$string;
Branch: 1 branch
BranchTrueFalseTotal
ref $string ? : 0 0 0
150 0 return (1);
151 }
152 0 return ($self->{TWS});
153 }
154  
155 10 1;
156 __END__
« Bind8/DB/Record.pm ↑ Summary Bind8/DB/A.pm »