| 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 |  | 625459 | use strict; | 
|  | 9 |  |  |  |  | 111 |  | 
|  | 9 |  |  |  |  | 245 |  | 
| 8 | 9 |  |  | 9 |  | 49 | use warnings; | 
|  | 9 |  |  |  |  | 11 |  | 
|  | 9 |  |  |  |  | 203 |  | 
| 9 | 9 |  |  | 9 |  | 41 | use Carp; | 
|  | 9 |  |  |  |  | 16 |  | 
|  | 9 |  |  |  |  | 492 |  | 
| 10 | 9 |  |  | 9 |  | 4862 | use File::ShareDir qw(module_dir); | 
|  | 9 |  |  |  |  | 239556 |  | 
|  | 9 |  |  |  |  | 505 |  | 
| 11 | 9 |  |  | 9 |  | 80 | use Exporter qw(import); | 
|  | 9 |  |  |  |  | 19 |  | 
|  | 9 |  |  |  |  | 2279 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | require DynaLoader; | 
| 14 |  |  |  |  |  |  | our @ISA = qw(DynaLoader); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our $VERSION = '0.40'; | 
| 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 | 466 | my ($pkg, $mode) = @_; | 
| 22 | 9 | 100 |  |  |  | 41 | if(!defined($mode)) { $mode = 0 } | 
|  | 1 |  |  |  |  | 2 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 9 |  |  |  |  | 54 | my $dd = module_dir('IP::World'); | 
| 25 | 9 | 50 |  |  |  | 4348 | 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 |  |  | 275 | 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 |  |  |  |  | 4066 | my $self = allocNew ($filepath, $fileLen, $mode); | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # bless the value from allocNew to be an object, and return it | 
| 37 | 9 |  |  |  |  | 49 | bless (\$self, $pkg); | 
| 38 | 9 |  |  |  |  | 39 | return \$self; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 1 |  |  | 1 | 1 | 81 | sub IP_WORLD_FAST { 0 } | 
| 42 | 1 |  |  | 1 | 1 | 93 | sub IP_WORLD_MMAP { 1 } | 
| 43 | 1 |  |  | 1 | 1 | 97 | sub IP_WORLD_TINY { 2 } | 
| 44 | 1 |  |  | 1 | 1 | 87 | 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 |