File Coverage

IP/World/Builder.pm
Criterion Covered Total %
statement 9 64 14.0
branch 0 38 0.0
condition 0 20 0.0
subroutine 3 4 75.0
pod 0 1 0.0
total 12 127 9.4


line stmt bran cond sub pod time code
1             # this package is used by Build.PL
2              
3             package IP::World::Builder;
4              
5 1     1   12 use strict;
  1         21  
  1         62  
6 1     1   9 use warnings;
  1         10  
  1         100  
7 1     1   13 use File::Copy;
  1         2  
  1         1596  
8              
9             # this is called during each Build step
10             sub do_dat {
11 0     0 0   my $self = $_[0];
12 0           my $invoked = $self->invoked_action();
13 0           my $current = $self->current_action();
14              
15 0 0         if ($current eq 'code') {
16              
17             # create destination directories as necessary
18 0           my $dest = '';
19 0           for ('blib/lib/auto', '/IP', '/World') {
20 0 0         if (!-d ($dest .= $_)) {
21 0 0         mkdir $dest or die "Can't make dir $dest: $!";
22             } }
23 0           $dest .= '/ipworld.dat';
24              
25             # select source file based on this machine's endianness
26 0           my $bigend = pack('L', 1) eq pack('N', 1);
27 0           my $srcdir = 'lib/auto/IP/World';
28 0 0         my $src = "$srcdir/ipworld." .($bigend ? 'be' : 'le');
29              
30             # get the proper mod time for the file from an accompanying file
31 0           my ($src_mod, $dest_mod);
32 0           my $fn = "$srcdir/modtime.dat";
33 0 0         open DAT, "<$fn" or die "Can't open $fn for read: $!";
34 0 0         read (DAT, $src_mod, 4)==4 or die "Can't read from $fn: $!";
35 0           close DAT;
36 0           $src_mod = unpack 'N', $src_mod;
37              
38             # set the mod times of the included files (in case someone copies)
39             # Windows requires write permission
40 0           my $WIN = $^O =~ /(ms|cyg)win/i;
41 0           for ('be', 'le') {
42 0           $fn = "$srcdir/ipworld.$_";
43 0 0 0       $WIN and chmod(0664, $fn) || die "Can't change permissions on $fn: $!";
44 0 0         utime($src_mod, $src_mod, $fn) || die "Can't set mod time of $fn: $!";
45 0 0 0       $WIN and chmod(0444, $fn) || die "Can't change permissions on $fn: $!";
46             }
47             # copy database if necessary
48 0 0 0       if (!-e $dest
      0        
      0        
49             || $src_mod > ($dest_mod = (CORE::stat $dest)[9])
50             || $src_mod == $dest_mod
51             && -s $src != -s $dest) {
52              
53             # copy the file
54 0           print "Copying $src -> $dest\n";
55 0 0         copy ($src, $dest) || die "Can't copy $src to $dest: $!";
56 0 0 0       $WIN and chmod(0664, $dest) || die "Can't change permissions on $dest: $!";
57 0 0         utime($src_mod, $src_mod, $dest) || die "Can't set mod time of $dest: $!";
58 0 0 0       $WIN and chmod(0444, $dest) || die "Can't change permissions on $dest: $!";
59             }
60             # hopefully temporary (if the M::B guys include docs in test)
61 0 0         if ($invoked eq 'test') {$self->depends_on('docs')}
  0            
62             }
63 0 0         if ($invoked eq 'install') {
64              
65             # run maint_ip_world_db to update the database if necessary
66 0 0         my $tail = $self->is_unixish() ? ' 2>&1' : '';
67 0           my $perl = $self->config_data('perl');
68 0 0         if (!$perl) {die "Can't get path to perl"}
  0            
69 0           my $fn = 'script/maint_ip_world_db';
70              
71 0           print "Checking for database update (may rebuild)...\n";
72              
73 0           my $result = `$perl $fn -t$tail`;
74 0   0       while ($result && $result =~ /^PROXY\t(.+?)\t(.*)/) {
75              
76             # maint_ip_world_db has encountered a proxy, but since it doesn't have
77             # a STDIN, we have to ask for the user and PW
78 0           my $netloc = $2;
79 0           print STDERR "Enter username for proxy $1 at $netloc: ";
80 0           my $u = ;
81 0           chomp($u);
82 0           print STDERR "Password: ";
83 0           system("stty -echo");
84 0           my $pw = ;
85 0           system("stty echo");
86 0           print STDERR "\n"; # because we disabled echo
87 0           chomp($pw);
88 0           $result = `$perl $fn -t -u "$u" -p "$pw"$tail`;
89             }
90 0 0         if (!defined $result) {die "execution of $fn failed: $!"}
  0            
91 0           print $result;
92              
93             } } # end sub process_dat_file
94             1;