Zone.pm

filter: Statementstmt 36.7% 40 / 109 Branchbran 12.5% 5 / 40 Conditioncond 9.5% 2 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 55.5% 10 / 18 Podpod 0.0% 0 / 12 totaltotal 26.6% 57 / 214 CC 35 SCAR 36.9
CC
35
Cov
28%
sort
110.0
dump
72.0
delete
30.0
CRAP 40.1
« Zone/Label.pm ↑ Summary Zone/Record.pm »
1 #!/usr/local/bin/perl -w
2 ######################################################################
3 #
4 # DNS/Zone.pm
5 #
6 # $Id: Zone.pm,v 1.7 2003/02/04 15:22:12 awolf Exp $
7 # $Revision: 1.7 $
8 # $Author: awolf $
9 # $Date: 2003/02/04 15:22:12 $
10 #
11 # Copyright (C)2001-2003 Andy Wolf. All rights reserved.
12 #
13 # This library is free software; you can redistribute it and/or
14 # modify it under the same terms as Perl itself.
15 #
16 ######################################################################
17  
18 package DNS::Zone;
19  
20 2 ▶no warnings 'portable';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use 5.6.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 my $VERSION = '0.85';
28 2 my $REVISION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
29  
30 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
31 1 my($pkg, $name) = @_;
32 1 ▶ my $class = ref($pkg) || $pkg;
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
33  
34 1 my $self = {
35 '_ID' => undef,
36 'NAME' => $name,
37 'LABELS' => [],
38 };
39
40 1 bless $self, $class;
41
42 1 return $self;
43 }
44  
45 # The id shall only be used to search if
46 # the backend allows to use ids more
47 # efficiently. Setting this attribute
48 # should only be done when reading/writing
49 # from/to the backend (e.g. database)
50 ########################################
51 0 ▶sub id {
Subroutine id: not called CC=2 SCAR=17.9
Pod undocumented
52 0 my($self, $id) = @_;
53
54 0 ▶ $self->{'_ID'} = $id if($id);
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
55
56 0 return($self->{'_ID'});
57 }
58  
59 0 ▶sub name {
Subroutine name: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my($self, $name) = @_;
61
62 0 ▶ $self->{'NAME'} = $name if($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
63
64 0 return($self->{'NAME'});
65 }
66  
67 #May be used to store a reference to some super
68 #object like a master server.
69 0 ▶sub master {
Subroutine master: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my($self, $ref) = @_;
71
72 0 ▶ $self->{'MASTER'} = $ref if($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
73
74 0 return $self->{'MASTER'};
75 }
76  
77 4 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
78 4 my($self, $label) = @_;
79
80 4 push @{ $self->{'LABELS'} }, ($label);
81
82 4 return $label;
83 }
84  
85 0 ▶sub delete {
Subroutine delete: not called CC=5 SCAR=34.0
Pod undocumented
86 0 my($self, $record) = @_;
87
88 0 my $found = 0;
89
90 0 foreach my $label ($self->labels()) {
91 0 my @array = $label->records();
92  
93 0 ▶ for (my $i=0 ; $array[$i] ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array[$i]) 0 0 0
94 0 ▶ if($array[$i] == $record) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array[$i] == $record) 0 0 0
95 0 $found = 1;
96 0 splice @array, $i, 1;
97 }
98 }
99  
100 0 $label->records(@array);
101 }
102
103 0 ▶ return $found ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 0 0
104 }
105  
106 15 ▶sub label {
Subroutine label: called CC=9 SCAR=31.0
Pod undocumented
107 15 my($self, $ref) = @_;
108 15 my $label;
109  
110 15 ▶ if(exists $ref->{'NAME'} && $ref->{'NAME'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $ref->{'NAME'} and $ref->{'NAME'}) { } 15 0 15
elsif (exists $ref->{'ID'} and $ref->{'ID'}) { } 0 0 0
Condition33%1/3
exists $ref->{"NAME"} and $ref->{"NAME"}
!ll&&!rl&&r
0015
MC/DC0%0/2
exists $ref->{"NAME"} and $ref->{"NAME"}
exists $ref->{"NAME"} $ref->{"NAME"}
Truth table33%1/3
A and B
A= exists $ref->{"NAME"}B= $ref->{"NAME"}
ABresult
0X0
100
111
111 15 for ($self->labels()) {
112 29 ▶ $label = $_ if($_->label() eq $ref->{'NAME'});
Branch: 1 branch
BranchTrueFalseTotal
if $_->label eq $ref->{"NAME"} 11 18 29
113 }
114 }
115 ▶ elsif(exists $ref->{'ID'} && $ref->{'ID'}) {
Condition0%0/3
exists $ref->{"ID"} and $ref->{"ID"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ref->{"ID"} and $ref->{"ID"}
exists $ref->{"ID"} $ref->{"ID"}
Truth table0%0/3
A and B
A= exists $ref->{"ID"}B= $ref->{"ID"}
ABresult
0X0
100
111
116 0 for ($self->labels()) {
117 0 ▶ $label = $_ if($_->id() eq $ref->{'ID'});
Branch: 1 branch
BranchTrueFalseTotal
if $_->id eq $ref->{"ID"} 0 0 0
118 }
119 }
120
121 15 return $label;
122 }
123
124 16 ▶sub labels {
Subroutine labels: called CC=3 SCAR=11.3
Pod undocumented
125 16 my($self, @labels) = @_;
126
127 16 ▶ $self->{'LABELS'} = \@labels if(scalar @labels);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @labels 0 16 16
128
129 16 ▶ my @result = @{ $self->{'LABELS'} } if(ref($self->{'LABELS'}) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"LABELS"} eq "ARRAY" 16 0 16
130  
131 16 return @result;
132 }
133  
134 0 ▶sub sort {
Subroutine sort: not called CC=10 SCAR=47.0
Pod undocumented
135 0 my($self) = @_;
136  
137 my @result = sort {
138 0 my(@a) = reverse split /\./, $a->label();
139 0 my(@b) = reverse split /\./, $b->label();
140
141 0 ▶ for(my $i=0 ; $a[$i] || $b[$i] ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[$i] or $b[$i]) 0 0 0
Condition0%0/3
$a[$i] or $b[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$a[$i] or $b[$i]
$a[$i] $b[$i]
Truth table0%0/3
A or B
A= $a[$i]B= $b[$i]
ABresult
1X1
011
000
142 0 ▶ if($a[$i] && $b[$i]) {
Branch: 3 branches
BranchTrueFalseTotal
if ($a[$i] and $b[$i]) { } 0 0 0
elsif ($a[$i] and not $b[$i]) { } 0 0 0
elsif (not $a[$i] and $b[$i]) { } 0 0 0
Condition0%0/3
$a[$i] and $b[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$a[$i] and $b[$i]
$a[$i] $b[$i]
Truth table0%0/3
A and B
A= $a[$i]B= $b[$i]
ABresult
0X0
100
111
143 0 ▶ return ($a[$i] cmp $b[$i]) if($a[$i] cmp $b[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $a[$i] cmp $b[$i] 0 0 0
144 }
145 ▶ elsif($a[$i] && !$b[$i]) {
Condition0%0/3
$a[$i] and not $b[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
$a[$i] and not $b[$i]
$a[$i] not $b[$i]
Truth table0%0/3
A and not(B)
A= $a[$i]B= not $b[$i]
ABresult
0X0
100
111
146 0 return 1;
147 }
148 ▶ elsif(!$a[$i] && $b[$i]) {
Condition0%0/3
not $a[$i] and $b[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
not $a[$i] and $b[$i]
not $a[$i] $b[$i]
Truth table0%0/3
not(A) and B
A= not $a[$i]B= $b[$i]
ABresult
0X0
100
111
149 0 return -1;
150 }
151 else {
152 0 return 0;
153 }
154 }
155
156 0 return 0;
157 } $self->labels();
158  
159 0 $self->labels(@result);
160
161 0 return $self;
162 }
163  
164 0 ▶sub dump {
Subroutine dump: not called CC=8 SCAR=42.8
Pod undocumented
165 0 my($self) = @_;
166  
167 0 my %ttl_hash;
168 0 my $labellength = 0;
169 0 for my $label ($self->sort()->labels()) {
170 0 my $length = length $label->label();
171 0 ▶ $labellength = $length if($length > $labellength);
Branch: 1 branch
BranchTrueFalseTotal
if $length > $labellength 0 0 0
172
173 0 my @records = $label->records();
174
175 0 for (@records) {
176 0 my $ttl = $_->ttl();
177
178 0 ▶ if(exists $ttl_hash{$ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ttl_hash{$ttl}) { } 0 0 0
179 0 $ttl_hash{$ttl} += 1;
180 }
181 else {
182 0 $ttl_hash{$ttl} = 1;
183 }
184 }
185 }
186  
187 0 my $ttl_default = 0;
188 0 my $ttl_max = 0;
189 0 for (keys %ttl_hash) {
190 0 ▶ $ttl_default = $_ if($ttl_hash{$_} > $ttl_max);
Branch: 1 branch
BranchTrueFalseTotal
if $ttl_hash{$_} > $ttl_max 0 0 0
191 }
192
193 0 my $origin = $self->name();
194
195 0 print '$TTL ', "$ttl_default\n";
196 0 print '$ORIGIN ', "$origin\.\n";
197
198 0 foreach my $label ($self->labels()) {
199 0 print "\n";
200 0 $label->dump("%-" . $labellength . "s", $origin, $ttl_default);
201 }
202  
203 0 return $self;
204 }
205  
206 0 ▶sub toXML {
Subroutine toXML: not called CC=1 SCAR=6.9
Pod undocumented
207 0 my($self) = @_;
208 0 my $result;
209
210 0 $result .= qq(<Zone id=") . $self->id() . qq(" managed="1">\n);
211 0 $result .= qq(<Name>\n) . $self->name() . qq(</Name>\n);
212  
213 0 map { $result .= $_->toXML() } $self->labels();
214  
215 0 $result .= qq(</Zone>\n);
216  
217 0 return $result;
218 }
219  
220 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=1.7
Pod undocumented
221 0 my($self) = @_;
222  
223 0 eval {
224 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
225
226 0 print Dumper($self);
227 };
228
229 0 return $self;
230 }
231  
232 2 1;
233  
234 __END__
« Zone/Label.pm ↑ Summary Zone/Record.pm »