Maker/Eval/DNSSerial.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 70 CC 7 SCAR 33.0
CC
7
Cov
0%
_dns_serial
56.0
dns_serial
2.0
dns_daily_serial
2.0
CRAP 27.2
1 package Config::Maker::Eval;
2  
3 use utf8;
4 use warnings;
5 use strict;
6  
7 use Carp;
8 use POSIX qw(strftime);
9  
10 {
11 my %cache;
12 sub _dns_serial {
13 my ($daily) = @_;
14 my $file = Get1('META:output');
15 my $serial;
16 return $cache{$file} if $cache{$file};
17  
18 if(open IN, '<', $file) {
19 local $_; # WARNING! while does NOT auto-localize
20 while(<IN>) {
21 if(/^\s*(\d+)\s*;\s*serial\s*$/) {
22 $serial = $1;
23 last;
24 }
25 }
26 close IN;
27 } else {
28 warn "Couldn't open $file: $!";
29 $serial = 0;
30 }
31
32 die "Serial not found" unless defined $serial;
33  
34 if($daily) {
35 my $now = strftime '%Y%m%d00', localtime;
36 $serial = $now if $serial < $now;
37 }
38 warn "Daily: $daily, Serial: $serial";
39  
40 return $cache{$file} = $serial + 1;
41 }
42  
43 sub dns_serial { _dns_serial(0) }
44 sub dns_daily_serial { _dns_serial(1) }
45  
46 sub lastbyte {
47 my ($ip) = @_;
48 $ip =~ /\.(\d+)$/ or die "IP $ip does not match \\.(\\d)\$";
49 return $1;
50 }
51 }
52  
53 1;
54  
55 __END__