1#!/usr/local/bin/perl -w 2###################################################################### 3# 4# DNS/Zone/File.pm 5# 6# $Id: File.pm,v 1.8 2003/02/04 15:37:34 awolf Exp $ 7# $Revision: 1.8 $ 8# $Author: awolf $ 9# $Date: 2003/02/04 15:37:34 $ 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 18package DNS::Zone::File; 19 20use strict; 21 22use DNS::Zone; 23use DNS::Zone::Label; 24use DNS::Zone::Record; 25 26my $VERSION = '0.85'; 27my $REVISION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/); 28 29my $map = { 30 'default' => 'DNS::Zone::File::Default' 31}; 32 33sub new { 34 my($pkg, %hash) = @_; 35 my $ref; 36 37 my $type = $hash{'type'} || 'default'; 38 my $zone = $hash{'zone'}; 39 my $file = $hash{'file'}; 40 41 eval "require $map->{$type}"; 42 43 if(!$@) { 44 $ref = $map->{$type}->new($zone, $file); 45 } 46 else { 47 warn $@; 48 } 49 50 return $ref; 51} 52 53sub read { 54 my($self, $file) = @_; 55 my @lines; 56 57 $file = $file || $self->{'FILE'}; 58 59 if(open(FILE, $file)) { 60 @lines = <FILE>; 61 chomp @lines; 62 close FILE; 63 } 64 else { warn "Cannot read file $file !"; } 65 66 return @lines; 67} 68 69sub parse { 70 my($self, $file) = @_; 71 72 # Overwrite in sub classes ! 73 74 return $self; 75} 76 77sub dump { 78 my($self, $file) = @_; 79 80 # Overwrite in sub classes ! 81 82 return $self; 83} 84 85sub debug { 86 my($self) = @_; 87 88 eval { 89 use Data::Dumper; 90 91 print Dumper($self); 92 }; 93 94 return $self; 95} 96 971; 98 99__END__ 100 101=pod 102 103=head1 NAME 104 105DNS::Zone::File - Abstract file class 106 107 108=head1 SYNOPSIS 109 110use DNS::Zone::File; 111 112my $file = new DNS::Zone::File( 113 'type' => 'default', 114 'zone' => $zone_name_string, 115 'file' => $file_name_string 116); 117 118# Parse an existing zonefile 119$file->parse(); 120$file->parse($other_file_name_string); 121 122# Dump data to existing or new file 123$file->dump(); 124$file->dump($other_file_name_string); 125 126# Get DNS::Zone object 127my $zone = $file->zone(); 128 129 130=head1 ABSTRACT 131 132This abstract class represents the interface to specific 133configuration file adaptor classes. 134 135 136=head1 DESCRIPTION 137 138An adaptor class for a specific configuration file encapsulates 139the logic required for writing (dump) and reading (parse) the 140configuration of a certain name service daemon implementation. 141 142To provide a common interface to all those adaptors already 143available and probably upcoming, this abstract class declares 144the methods required. 145 146This class is also a factory which shields the concrete adaptor 147class from its user by the use of a type map which maps a 148keyword to an implementation class that has to be a subclass 149of this abstract class. 150 151 152=head1 AUTHOR 153 154Copyright (C)2001-2003 Andy Wolf. All rights reserved. 155 156This library is free software; you can redistribute it and/or 157modify it under the same terms as Perl itself. 158 159Please address bug reports and comments to: 160zonemaster@users.sourceforge.net 161 162 163=head1 SEE ALSO 164 165L<DNS::Zone::File::Default> 166 167 168=cut 169