ZoneParse/Generator/DNSZoneParse.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 69 CC 4 SCAR 16.4
CC
4
Cov
0%
generate
12.0
_unmap
6.0
BEGIN
2.0
CRAP 5.2
1 package Net::DNS::ZoneParse::Generator::DNSZoneParse;
2  
3 use 5.008000;
4 use strict;
5 use warnings;
6 use vars qw($VERSION);
7  
8 use Net::DNS;
9 use DNS::ZoneParse;
10 use Net::DNS::ZoneParse::Parser::DNSZoneParse;
11  
12 my %soamap = %Net::DNS::ZoneParse::Parser::DNSZoneParse::soamap;
13 my %rrmap = %Net::DNS::ZoneParse::Parser::DNSZoneParse::rrmap;
14  
15 $VERSION = 0.103;
16  
17 =pod
18  
19 =head1 NAME
20  
21 Net::DNS::ZoneParse::Generator::DNSZoneParse - generator glue for
22 Net::DNS::ZoneParse to use DNS::ZoneParse.
23  
24 =head1 DESCRIPTION
25  
26 =cut
27  
28 my %type = (
29 SOA => sub {
30 my ($rr, $zone) = @_;
31 my $soa = $zone->soa();
32 map { $soa->{$soamap{$_}} = $rr->{$_} } keys %soamap;
33 },
34 );
35  
36 sub _unmap {
37 my ($rr, $zone) = @_;
38 my $type = lc($rr->{type});
39 return unless $rrmap{$type};
40 my $list = eval("\$zone->$type()");
41 push(@{$list}, { map { $rrmap{$type}->{$_} => $rr->{$_} }
42 keys %{$rrmap{$type}} });
43 }
44  
45 =pod
46  
47 =head2 EXPORT
48  
49 =head3 generate
50  
51 This will be called by the Interface of Net::DNS:ZoneParse and return the
52 corresponding zonetext.
53  
54 =cut
55  
56 sub generate {
57 my ($self, $param) = @_;
58  
59 my $text = "";
60 my $zone = $param->{parser_arg}->{zone};
61 if($zone) {
62 for(keys %rrmap) {
63 my $ref = eval("\$zone->$_");
64 pop(@{$ref}) while($#{$ref} >= 0);
65 }
66 } else {
67 $zone = DNS::ZoneParse->new(\$text, $param->{origin});
68 }
69 map { $type{$_->{type}}?$type{$_->{type}}($_, $zone):_unmap($_, $zone) } @{$param->{rr}};
70 return $zone->output();
71 }
72  
73 =pod
74  
75 =head1 SEE ALSO
76  
77 Net::DNS::ZoneParse
78 DNS::ZoneParse
79  
80 =head1 AUTHOR
81  
82 Benjamin Tietz E<lt>benjamin@micronet24.deE<gt>
83  
84 =head1 COPYRIGHT
85  
86 Copyright (C) 2010 by Benjamin Tietz
87  
88 This library is free software; you can redistribute it and/or modify
89 it under the same terms as Perl itself, either Perl version 5.10.0 or,
90 at your option, any later version of Perl 5 you may have available.
91  
92 =cut
93  
94 1;