Zone/Label.pm

filter: Statementstmt 33.0% 34 / 103 Branchbran 4.2% 3 / 70 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 56.2% 9 / 16 Podpod 0.0% 0 / 11 totaltotal 21.8% 47 / 215 CC 40 SCAR 52.4
CC
40
Cov
21%
sort
462.0
record
56.0
dump
30.0
CRAP 188.5
↑ Summary Zone.pm »
1 #!/usr/local/bin/perl -w
2 ######################################################################
3 #
4 # DNS/Zone/Label.pm
5 #
6 # $Id: Label.pm,v 1.5 2003/02/04 15:37:35 awolf Exp $
7 # $Revision: 1.5 $
8 # $Author: awolf $
9 # $Date: 2003/02/04 15:37:35 $
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::Label;
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 my $VERSION = '0.85';
26 2 my $REVISION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
27  
28 ###
29 # The label name is always relative to
30 # the zone name. Default type is '' and
31 # represents a comment.
32 ###
33 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
34 4 my($pkg, $label) = @_;
35 4 ▶ my $class = ref($pkg) || $pkg;
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
36  
37 4 my $self = {
38 '_ID' => undef,
39 'LABEL' => $label,
40 'RECORDS' => [],
41 };
42  
43 4 bless($self, $class);
44  
45 4 return $self;
46 }
47  
48 0 ▶sub id {
Subroutine id: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my($self, $id) = @_;
50
51 0 ▶ $self->{'_ID'} = $id if($id);
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
52
53 0 return($self->{'_ID'});
54 }
55  
56 29 ▶sub label {
Subroutine label: called CC=2 SCAR=7.1
Pod undocumented
57 29 my($self, $label) = @_;
58
59 29 ▶ $self->{'LABEL'} = $label if($label);
Branch: 1 branch
BranchTrueFalseTotal
if $label 0 29 29
60
61 29 return($self->{'LABEL'});
62 }
63  
64 17 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
65 17 my($self, $record) = @_;
66
67 17 push @{ $self->{'RECORDS'} }, ($record);
68
69 17 return $record;
70  
71 }
72  
73 0 ▶sub delete {
Subroutine delete: not called CC=4 SCAR=30.0
Pod undocumented
74 0 my($self, $record) = @_;
75
76 0 my $found = 0;
77 0 my @array = $self->records();
78
79 0 ▶ for (my $i=0 ; $array[$i] ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array[$i]) 0 0 0
80 0 ▶ if($array[$i] == $record) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array[$i] == $record) 0 0 0
81 0 $found = 1;
82 0 splice @array, $i, 1;
83 }
84 }
85  
86 0 $self->records(@array);
87
88 0 ▶ return $found ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 0 0
89 }
90  
91 0 ▶sub record {
Subroutine record: not called CC=7 SCAR=40.3
Pod undocumented
92 0 my($self, $ref) = @_;
93 0 my $record;
94  
95 0 ▶ if(exists $ref->{'ID'} && $ref->{'ID'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $ref->{'ID'} and $ref->{'ID'}) { } 0 0 0
elsif (exists $ref->{'TYPE'} and $ref->{'TYPE'}) { } 0 0 0
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
96 0 ▶ map { $record = $_ if($_->id() eq $ref->{'ID'}) } $self->records();
Branch: 1 branch
BranchTrueFalseTotal
if $_->id eq $ref->{"ID"} 0 0 0
97 }
98 ▶ elsif(exists $ref->{'TYPE'} && $ref->{'TYPE'}) {
Condition0%0/3
exists $ref->{"TYPE"} and $ref->{"TYPE"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ref->{"TYPE"} and $ref->{"TYPE"}
exists $ref->{"TYPE"} $ref->{"TYPE"}
Truth table0%0/3
A and B
A= exists $ref->{"TYPE"}B= $ref->{"TYPE"}
ABresult
0X0
100
111
99 0 ▶ map { $record = $_ if($_->type() eq $ref->{'TYPE'}) } $self->records();
Branch: 1 branch
BranchTrueFalseTotal
if $_->type eq $ref->{"TYPE"} 0 0 0
100 }
101
102 0 return $record;
103 }
104  
105 8 ▶sub records {
Subroutine records: called CC=3 SCAR=11.3
Pod undocumented
106 8 my($self, @records) = @_;
107
108 8 ▶ $self->{'RECORDS'} = \@records if(scalar @records);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @records 0 8 8
109
110 8 ▶ my @result = @{ $self->{'RECORDS'} } if(ref($self->{'RECORDS'}) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"RECORDS"} eq "ARRAY" 8 0 8
111  
112 8 return @result;
113 }
114  
115 0 ▶sub dump {
Subroutine dump: not called CC=5 SCAR=34.0
Pod undocumented
116 0 my($self, $format, $origin, $ttl_default) = @_;
117  
118 0 my @records = $self->sort()->records();
119
120 0 my $label = $self->{'LABEL'};
121 0 $label =~ s/\.$origin\.*$//;
122 0 ▶ $label = '@' if($label eq $origin);
Branch: 1 branch
BranchTrueFalseTotal
if $label eq $origin 0 0 0
123
124 0 my $first = 1;
125 0 foreach my $record (@records) {
126 0 ▶ $label = $first ? $label : '';
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
127
128 0 $record->dump($label, $format, $ttl_default);
129
130 0 ▶ $first = 0 if($record->type() ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $record->type ne "" 0 0 0
131 }
132
133 0 return $self;
134 }
135  
136 0 ▶sub toXML {
Subroutine toXML: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my($self) = @_;
138 0 my $result;
139
140 0 $result .= qq(<Label id=") . $self->id() . qq(">\n);
141 0 $result .= qq(<Name>\n) . $self->label() . qq(</Name>\n);
142  
143 0 map { $result .= $_->toXML() } $self->records();
144  
145 0 $result .= qq(</Label>\n);
146
147 0 return $result;
148 }
149  
150 0 ▶sub debug {
Subroutine debug: not called CC=2 SCAR=12.2
Pod undocumented
151 0 my($self) = @_;
152
153 0 ▶ return undef unless($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
154
155 0 eval {
156 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
157
158 0 print Dumper($self);
159 };
160
161 0 return $self;
162 }
163  
164 0 ▶sub sort {
Subroutine sort: not called CC=21 SCAR=61.4
Pod undocumented
165 0 my($self) = @_;
166
167 my @result = sort {
168 0 ▶ return 1 if($b->type() eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "" 0 0 0
169 0 ▶ return -1 if($a->type() eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "" 0 0 0
170 0 ▶ return 1 if($b->type() eq 'IN SOA');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN SOA" 0 0 0
171 0 ▶ return -1 if($a->type() eq 'IN SOA');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN SOA" 0 0 0
172 0 ▶ return 1 if($b->type() eq 'IN A');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN A" 0 0 0
173 0 ▶ return -1 if($a->type() eq 'IN A');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN A" 0 0 0
174 0 ▶ return 1 if($b->type() eq 'IN NS');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN NS" 0 0 0
175 0 ▶ return -1 if($a->type() eq 'IN NS');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN NS" 0 0 0
176 0 ▶ return 1 if($b->type() eq 'IN MX');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN MX" 0 0 0
177 0 ▶ return -1 if($a->type() eq 'IN MX');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN MX" 0 0 0
178 0 ▶ return 1 if($b->type() eq 'IN CNAME');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN CNAME" 0 0 0
179 0 ▶ return -1 if($a->type() eq 'IN CNAME');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN CNAME" 0 0 0
180 0 ▶ return 1 if($b->type() eq 'IN TXT');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN TXT" 0 0 0
181 0 ▶ return -1 if($a->type() eq 'IN TXT');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN TXT" 0 0 0
182 0 ▶ return 1 if($b->type() eq 'IN PTR');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN PTR" 0 0 0
183 0 ▶ return -1 if($a->type() eq 'IN PTR');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN PTR" 0 0 0
184 0 ▶ return 1 if($b->type() eq 'IN HINFO');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN HINFO" 0 0 0
185 0 ▶ return -1 if($a->type() eq 'IN HINFO');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN HINFO" 0 0 0
186 0 ▶ return 1 if($b->type() eq 'IN WKS');
Branch: 1 branch
BranchTrueFalseTotal
if $b->type eq "IN WKS" 0 0 0
187 0 ▶ return -1 if($a->type() eq 'IN WKS');
Branch: 1 branch
BranchTrueFalseTotal
if $a->type eq "IN WKS" 0 0 0
188  
189 0 return 0;
190 } $self->records();
191
192 0 $self->records(@result);
193  
194 0 return $self;
195 }
196  
197 2 1;
198  
199 __END__
↑ Summary Zone.pm »