File Coverage

blib/lib/DNS/Config/Statement/Zone.pm
Criterion Covered Total %
statement 18 85 21.1
branch 0 26 0.0
condition 0 15 0.0
subroutine 6 15 40.0
pod 0 9 0.0
total 24 150 16.0


line stmt bran cond sub pod time code
1             #!/usr/local/bin/perl -w
2             ######################################################################
3             #
4             # DNS/Config/Statement/Zone.pm
5             #
6             # $Id: Zone.pm,v 1.4 2003/02/16 10:15:33 awolf Exp $
7             # $Revision: 1.4 $
8             # $Author: awolf $
9             # $Date: 2003/02/16 10:15:33 $
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::Config::Statement::Zone;
19              
20 1     1   1678 no warnings 'portable';
  1         3  
  1         60  
21 1     1   19 use 5.6.0;
  1         5  
  1         55  
22 1     1   8 use strict;
  1         3  
  1         39  
23 1     1   8 use warnings;
  1         2  
  1         45  
24 1     1   7 use vars qw(@ISA);
  1         2  
  1         61  
25              
26 1     1   7 use DNS::Config::Statement;
  1         3  
  1         1486  
27              
28             @ISA = qw(DNS::Config::Statement);
29              
30             my $VERSION = '0.66';
31             my $REVISION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
32              
33             sub new {
34 0     0 0   my($pkg) = @_;
35 0   0       my $class = ref($pkg) || $pkg;
36              
37 0           my $self = {
38             'TYPE' => 'master'
39             };
40            
41 0           bless $self, $class;
42              
43 0           return $self;
44             }
45              
46             sub parse_tree {
47 0     0 0   my($self, @array) = @_;
48            
49 0 0 0       return undef if((scalar(@array) < 2) || (scalar(@array) > 3));
50            
51 0           $self->{'NAME'} = shift @array;
52 0           $self->{'NAME'} =~ s/^\"//g;
53 0           $self->{'NAME'} =~ s/\"$//g;
54            
55 0 0         if(!ref($array[0])) {
56 0           $self->{'CLASS'} = shift @array;
57 0           $self->{'CLASS'} =~ s/^\"//g;
58 0           $self->{'CLASS'} =~ s/\"$//g;
59             }
60            
61 0           my $data = shift @array;
62 0           my @data = @$data;
63              
64 0           foreach my $stmt (@data) {
65 0           my @stmt = @$stmt;
66            
67 0           my $key = uc shift @stmt;
68            
69 0 0         if(scalar(@stmt) == 1) {
70 0           $self->{$key} = shift @stmt;
71 0           $self->{$key} =~ s/^\"//g;
72 0           $self->{$key} =~ s/\"$//g;
73             }
74             else {
75 0           $self->{$key} = \@stmt;
76             }
77             }
78            
79 0           return $self;
80             }
81              
82             sub dump {
83 0     0 0   my($self) = @_;
84 0           my @array;
85            
86             my @array2;
87 0           foreach my $key (keys %$self) {
88 0 0 0       if(($key =~ /FILE/) || ($key =~ /DIRECTORY/)) {
    0 0        
89 0           push @array2, ([ lc $key, q(") . $self->{$key} . q(")]);
90             }
91             elsif(($key ne 'NAME') && ($key ne 'CLASS')) {
92 0           push @array2, ([ lc $key, $self->{$key}]);
93             }
94             }
95            
96 0           push @array, ('zone', q(") . $self->{'NAME'} . q("));
97 0 0         push @array, ($self->{'CLASS'}) if(exists $self->{'CLASS'});
98 0           push @array, (\@array2);
99            
100 0           my $string = $self->substatement(@array);
101 0           print $string, "\n";
102            
103 0           return $self;
104             }
105              
106             sub name {
107 0     0 0   my($self, $name) = @_;
108              
109 0 0         $self->{'NAME'} = $name if($name);
110            
111 0           return $self->{'NAME'};
112             }
113              
114             sub class {
115 0     0 0   my($self, $class) = @_;
116              
117 0 0         $self->{'CLASS'} = $class if($class);
118            
119 0           return $self->{'CLASS'};
120             }
121              
122             sub type {
123 0     0 0   my($self, $type) = @_;
124            
125 0 0 0       if((lc $type eq 'master') || (lc $type eq 'slave')) {
126 0           $self->{'TYPE'} = lc $type;
127             }
128            
129 0           return $self->{'TYPE'};
130             }
131            
132             sub file {
133 0     0 0   my($self, $file) = @_;
134            
135 0 0         $self->{'FILE'} = $file if($file);
136            
137 0           return $self->{'FILE'};
138             }
139              
140             sub masters {
141 0     0 0   my($self, @hosts) = @_;
142 0           my @result;
143              
144 0 0         if(scalar(@hosts)) {
145 0           $self->{'TYPE'} = 'slave';
146 0           $self->{'MASTERS'} = [ \@hosts ];
147             }
148            
149 0 0         if(uc $self->{'TYPE'} eq 'SLAVE') {
150 0           @result = @{ $self->{'MASTERS'} };
  0            
151             }
152              
153 0           return @result;
154             }
155              
156             sub master {
157 0     0 0   my($self, $host) = @_;
158            
159 0           my @temp = $self->masters( $host );
160              
161 0           my $pnserver;
162 0 0         if(scalar(@temp)) {
163 0           my @tmp = @{$temp[0]};
  0            
164 0           $pnserver = $tmp[0];
165             }
166            
167 0           return $pnserver;
168             }
169              
170             1;
171              
172             __END__