script/build_ipcc.pl untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 56 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 use strict;
3 use warnings;
4  
5 # PODNAME: build_ipcc.pl
6 # ABSTRACT: Build database for IP::Country::DB_File
7  
8 use Getopt::Std;
9 use IP::Country::DB_File::Builder;
10  
11 my %opts;
12 Getopt::Std::getopts('vfbrd:', \%opts) or exit(1);
13  
14 die("extraneous arguments\n") if @ARGV > 1;
15  
16 my $dir = $opts{d};
17 my $package = 'IP::Country::DB_File::Builder';
18  
19 eval {
20 $package->fetch_files($dir, $opts{v}) if $opts{f};
21  
22 if($opts{b}) {
23 print("Building database...\n") if $opts{v};
24  
25 my $builder = $package->new($ARGV[0]);
26 $builder->build($dir);
27  
28 if ($opts{v}) {
29 print("Total merged IPv4 ranges: ", $builder->num_ranges_v4, "\n");
30 print("Total merged IPv6 ranges: ", $builder->num_ranges_v6, "\n");
31  
32 # We define usable IPv4 address space as
33 # 1.0.0.0 - 223.255.255.255 excluding 127.0.0.0/8
34 my $num_addresses_v4 = $builder->num_addresses_v4;
35 print("Total IPv4 addresses: $num_addresses_v4\n");
36 printf(
37 "%.2f%% of usable IPv4 address space\n",
38 100 * $num_addresses_v4 / 0xde000000,
39 );
40 }
41 }
42 };
43  
44 if($@) {
45 print STDERR ($@);
46 }
47  
48 if($opts{r}) {
49 print("Removing statistics files\n") if $opts{v};
50 $package->remove_files($dir);
51 }
52  
53 __END__