ZoneParse/Generator/Native.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 57.1% 8 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 85.2% 52 / 61 CC 9 SCAR 16.0
CC
9
Cov
85%
_writerr
8.6
generate
3.0
BEGIN
1.0
CRAP 4.9
« ZoneParse/Generator/DNSZoneParse.pm ↑ Summary ZoneParse/Parser/Native/DNSext.pm »
1 package Net::DNS::ZoneParse::Generator::Native;
2  
3 2 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 $VERSION = 0.101;
11  
12 =pod
13  
14 =head1 NAME
15  
16 Net::DNS::ZoneParse::Generator::Native - Net::DNS::ZoneParse's native generator.
17  
18 =head1 DESCRIPTION
19  
20 The native generator generates valid files, which can be read by most parsers.
21 If the corresponding information is available, it will generate correct
22 $TTL and $ORIGIN directives and - at least for the name of the resource records
23 shorten the names, if applicable.
24  
25 =cut
26  
27 #####################
28 # private functions #
29 #####################
30  
31 # return one line of text for one RR
32 4 ▶sub _writerr {
Subroutine _writerr: called CC=7 SCAR=21.5
33 4 my ($rr, $zre, $ttl) = @_;
34 4 my $name = $rr->{name};
35 4 ▶ if($name =~ $zre) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /$zre/) { } 0 4 4
elsif (not $name =~ /\.$/) { } 4 0 4
36 0 $name = $1;
37 } elsif( $name !~ m/\.$/) {
38 4 $name .= ".";
39 }
40 4 ▶ $ttl = 0 unless $ttl;
Branch: 1 branch
BranchTrueFalseTotal
unless $ttl 4 0 4
41 4 ▶ $ttl = (($rr->{ttl} == $ttl)?"":$rr->{ttl}) || "";
Branch: 1 branch
BranchTrueFalseTotal
$rr->{'ttl'} == $ttl ? : 4 0 4
Condition50%1/2
($rr->{'ttl'} == $ttl ? '' : $rr->{'ttl'}) || ''
l!l
04
MC/DC0%0/1
($rr->{'ttl'} == $ttl ? '' : $rr->{'ttl'}) || ''
($rr->{'ttl'} == $ttl ? '' : $rr->{'ttl'})
Truth table50%1/2
A
A= ($rr->{'ttl'} == $ttl ? '' : $rr->{'ttl'})
Aresult
11
00
42 4 my $data = $rr->rdatastr;
43 4 ▶ $data = '; no data' unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 4 4
44 4 return join("\t", $name, $ttl, $rr->{class}, $rr->{type}, $data);
45 }
46  
47 =pod
48  
49 =head2 EXPORT
50  
51 =head3 generate
52  
53 This will be called by the Interface of Net::DNS:ZoneParse and return the
54 corresponding zonetext.
55  
56 =cut
57  
58 2 ▶sub generate {
Subroutine generate: called CC=3 SCAR=11.0
Pod documented
59 2 my ($self, $param) = @_;
60 2 my $ret = "";
61 2 my $zre = qr/^\(\)$/;
62 2 ▶ if($param->{origin}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"origin"}) 1 1 2
63 1 $ret .= "\$ORIGIN\t$param->{origin}\n";
64 1 $zre = qr/^(.*)\.$param->{origin}$/;
65 }
66 2 ▶ $ret .= "\$TTL\t$param->{ttl}\n" if($param->{ttl});
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"ttl"} 0 2 2
67 2 return $ret.join("\n", map { _writerr($_, $zre, $param->{ttl}); } @{$param->{rr}})."\n";
68 }
69  
70 =pod
71  
72 =head1 SEE ALSO
73  
74 Net::DNS::ZoneParse
75  
76 =head1 AUTHOR
77  
78 Benjamin Tietz E<lt>benjamin@micronet24.deE<gt>
79  
80 =head1 COPYRIGHT
81  
82 Copyright (C) 2010 by Benjamin Tietz
83  
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself, either Perl version 5.10.0 or,
86 at your option, any later version of Perl 5 you may have available.
87  
88 =cut
89  
90 2 1;
« ZoneParse/Generator/DNSZoneParse.pm ↑ Summary ZoneParse/Parser/Native/DNSext.pm »