line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IP::World; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# World.pm - the Perl part of the IP::World module |
4
|
|
|
|
|
|
|
# this module maps from IP addresses to country codes, using the free |
5
|
|
|
|
|
|
|
# WorldIP (wipmania.com) and GeoLite Country (maxmind.com) databases |
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
634570
|
use strict; |
|
9
|
|
|
|
|
100
|
|
|
9
|
|
|
|
|
278
|
|
8
|
9
|
|
|
9
|
|
48
|
use warnings; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
202
|
|
9
|
9
|
|
|
9
|
|
40
|
use Carp; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
477
|
|
10
|
9
|
|
|
9
|
|
4711
|
use File::ShareDir qw(module_dir); |
|
9
|
|
|
|
|
240150
|
|
|
9
|
|
|
|
|
530
|
|
11
|
9
|
|
|
9
|
|
86
|
use Exporter qw(import); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
2398
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require DynaLoader; |
14
|
|
|
|
|
|
|
our @ISA = qw(DynaLoader); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.42'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = qw(IP_WORLD_FAST IP_WORLD_MMAP IP_WORLD_TINY IP_WORLD_TINY_PERL); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
9
|
|
|
9
|
1
|
458
|
my ($pkg, $mode) = @_; |
22
|
9
|
100
|
|
|
|
41
|
if(!defined($mode)) { $mode = 0 } |
|
1
|
|
|
|
|
2
|
|
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
|
|
66
|
my $dd = module_dir('IP::World'); |
25
|
9
|
50
|
|
|
|
4364
|
if (!$dd) {croak "Can't locate directory containing database file"} |
|
0
|
|
|
|
|
0
|
|
26
|
9
|
|
|
|
|
36
|
my $filepath = "$dd/ipworld.dat"; |
27
|
9
|
|
|
|
|
18
|
my $fileLen; |
28
|
|
|
|
|
|
|
|
29
|
9
|
50
|
33
|
|
|
279
|
if (!-e $filepath |
30
|
|
|
|
|
|
|
|| !($fileLen = -s $filepath)) { |
31
|
0
|
|
|
|
|
0
|
croak "$filepath doesn't exist or has 0 length\n"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
# call the C (XS) part of new to read the file into memory |
34
|
9
|
|
|
|
|
3811
|
my $self = allocNew ($filepath, $fileLen, $mode); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# bless the value from allocNew to be an object, and return it |
37
|
9
|
|
|
|
|
51
|
bless (\$self, $pkg); |
38
|
9
|
|
|
|
|
43
|
return \$self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
1
|
90
|
sub IP_WORLD_FAST { 0 } |
42
|
1
|
|
|
1
|
1
|
115
|
sub IP_WORLD_MMAP { 1 } |
43
|
1
|
|
|
1
|
1
|
93
|
sub IP_WORLD_TINY { 2 } |
44
|
1
|
|
|
1
|
1
|
86
|
sub IP_WORLD_TINY_PERL { 3 } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# 'getcc' and 'DESTROY' are implemented in the IP/World.xs file. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
bootstrap IP::World $VERSION; |
49
|
|
|
|
|
|
|
1; # shows package is OK |