rkobes / apache-geoip

Look up country by IP address

This URL has Read+Write access

rkobes (author)
Thu Apr 23 20:36:04 -0700 2009
commit  6504106eba1eb9daee1a35bde46d4fda6e4b5633
tree    aac61cc1712cd225bb45429e100d05c82e3d7f23
parent  78692b088ee6273d4c17d92b611f9c9c51bee2c7
apache-geoip / Makefile.PL
100644 121 lines (107 sloc) 3.336 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
use Cwd;
use File::Copy;
use File::Path;
use File::Find;
use File::Basename;
require 5.006001;
 
my ($ans, @src_files);
 
my $prereq = {'Geo::IP' => '1.27'};
my ($libdir, $files_to_clean) = mp_copy();
 
push @$files_to_clean, 't/TEST';
 
my $name = ($libdir eq 'Apache') ? 'Apache::GeoIP' : 'Apache2::GeoIP';
 
my $eu_version = $ExtUtils::MakeMaker::VERSION;
my %opts = (
              NAME => $name,
              DISTNAME => 'Apache-GeoIP',
VERSION_FROM => "$libdir/GeoIP.pm",
              PREREQ_PM => $prereq,
($] >= 5.005 ?
               (ABSTRACT => 'Look up country by IP address',
                AUTHOR => 'Randy Kobes <r.kobes@uwinnipeg.ca>')
: ()),
clean => { FILES => "@$files_to_clean"},
              ($eu_version >= 6.11 ?
                (NO_META => 1,)
                : ()),
dist => {
SUFFIX => 'gz',
COMPRESS => 'gzip -9f',
},
           );
 
require Apache::TestMM;
import Apache::TestMM qw(test clean);
Apache::TestMM::filter_args();
Apache::TestMM::generate_script('t/TEST');
 
eval {require ModPerl::MM;};
if ($@) {
  WriteMakefile(%opts);
}
else {
  ModPerl::MM::WriteMakefile(%opts);
}
 
#######################################################################
# The following routine assumes the existence of two subdirectories:
# Apache: for mod_perl-1 things
# Apache2: for mod_perl-2 things
# which_modperl() is called to determine which of the two
# directories to use, depending on availability of
# mod_perl and/or user input. The files under the
# chosen directory are then copied under the lib/ directory
# for subsequent installation. If there is a t/ directory
# under either Apache/ or Apache2/, the files under
# this directory are copied beneath the top-level t/.
#
# The routine returns a list containing two items - which
# of the directories (Apache or Apache2) is used, and also
# an array reference of files copied to the lib/ or t/ directories
#
########################################################################
 
sub mp_copy {
  my $ans;
  my $apache_dir = which_modperl();
 
  @src_files = ();
  my @dest_files = ();
  finddepth(\&wanted, $apache_dir);
 
  foreach my $src (@src_files) {
    my $dir = dirname($src);
    my $dest_dir;
    if ($dir =~ m!/t/?(.*)!) {
      $dest_dir = "t/$1";
    }
    else {
      $dest_dir = 'lib/' . $dir;
    }
    unless (-d $dest_dir) {
      mkpath($dest_dir, 1, 0755) or die "mkpath $dest_dir failed: $!";
    }
    my $base = basename($src);
    my $dest_file = $dest_dir . '/' . $base;
    push @dest_files, $dest_file;
    my $key = $src;
    copy($src, $dest_file) or die "Cannot copy $src to $dest_file: $!";
  }
  return ($apache_dir, \@dest_files);
}
 
sub wanted {
  my $name = $File::Find::name;
  not (-d $_ or $name =~ m!CVS|svn!i) and push @src_files, $name;
}
 
sub which_modperl {
  my $ans;
  eval {require mod_perl2;};
  unless ($@) {
    $ans = prompt('Install mod_perl-2 version?', 'yes');
    return 'Apache2' if ($ans =~ /^y/);
  }
  eval {require Apache::src;};
  unless ($@) {
    $ans = prompt('Install mod_perl-1 version?', 'yes');
    return 'Apache' if ($ans =~ /^y/);
  }
  warn qq{Please install either mod_perl 1 or mod_perl 2 first};
  exit 0;
}