| 1 | package Geo::SypexGeo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.6'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Text::Trim; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Geo::SypexGeo::Info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | use fields qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | db_file b_idx_str m_idx_str range b_idx_len m_idx_len db_items id_len | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | block_len max_region max_city db_begin regions_begin cities_begin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | max_country country_size pack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | HEADER_LENGTH => 40, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my @COUNTRY_ISO_MAP = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | '', 'ap', 'eu', 'ad', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'cw', 'ao', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'aq', 'ar', 'as', 'at', 'au', 'aw', 'az', 'ba', 'bb', 'bd', 'be', 'bf', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'bg', 'bh', 'bi', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'by', 'bz', 'ca', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'cn', 'co', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'do', 'dz', 'ec', 'ee', 'eg', 'eh', 'er', 'es', 'et', 'fi', 'fj', 'fk', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'fm', 'fo', 'fr', 'sx', 'ga', 'gb', 'gd', 'ge', 'gf', 'gh', 'gi', 'gl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'gm', 'gn', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'in', 'io', 'iq', 'ir', 'is', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'it', 'jm', 'jo', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'lv', 'ly', 'ma', 'mc', 'md', 'mg', 'mh', 'mk', 'ml', 'mm', 'mn', 'mo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'ps', 'pt', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'pw', 'py', 'qa', 're', 'ro', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'sv', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tm', 'tn', 'to', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 'tl', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'um', 'us', 'uy', 'uz', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'rs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'za', 'zm', 'me', 'zw', 'a1', 'xk', 'o1', 'ax', 'gg', 'im', 'je', 'bl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'mf', 'bq', 'ss' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $self = fields::new( $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | open( my $fl, $file ) || croak( 'Could not open db file' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | binmode $fl, ':bytes'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | read $fl, my $header, HEADER_LENGTH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | croak 'File format is wrong' if substr( $header, 0, 3 ) ne 'SxG'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $info_str = substr( $header, 3, HEADER_LENGTH - 3 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my @info = unpack 'CNCCCnnNCnnNNnNn', $info_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | croak 'File header format is wrong' if $info[4] * $info[5] * $info[6] * $info[7] * $info[1] * $info[8] == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if ( $info[15] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | read $fl, my $pack, $info[15]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | $self->{pack} = [ split "\0", $pack ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | read $fl, $self->{b_idx_str}, $info[4] * 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | read $fl, $self->{m_idx_str}, $info[5] * 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $self->{range} = $info[6]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $self->{b_idx_len} = $info[4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $self->{m_idx_len} = $info[5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $self->{db_items} = $info[7]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $self->{id_len} = $info[8]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $self->{block_len} = 3 + $self->{id_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | $self->{max_region} = $info[9]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | $self->{max_city} = $info[10]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | $self->{max_country} = $info[13]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | $self->{country_size} = $info[14]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $self->{db_begin} = tell $fl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $self->{regions_begin} = $self->{db_begin} + $self->{db_items} * $self->{block_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $self->{cities_begin} = $self->{regions_begin} + $info[11]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $self->{db_file} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | close $fl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub get_city { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_city: called CC=6 SCAR=19.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my $lang = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my $seek = $self->get_num($ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | return unless $seek; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | my $info = $self->parse_info( $seek, $lang ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | return unless $info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $city; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if ( $lang && $lang eq 'en' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lang and $lang eq "en"
MC/DC0%0/2
$lang and $lang eq "en"
$lang
$lang eq "en"
Truth table33%1/3
A and B
A= $langB= $lang eq "en"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $city = $info->[6]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $city = $info->[5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | return unless $city; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | return decode_utf8($city); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | sub get_country { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_country: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $seek = $self->get_num($ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | return unless $seek; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my $info = $self->parse_info($seek); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | return unless $info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my $country = $COUNTRY_ISO_MAP[ $info->[1] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | return $country; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my $lang = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my $seek = $self->get_num($ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | return unless $seek; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | my $info = $self->parse_info($seek, $lang); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return Geo::SypexGeo::Info->new($info, $lang); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | sub get_num { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_num: called CC=11 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | my $ip1n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | $ip1n = int $ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | ▶ | return undef if !$ip1n || $ip1n == 10 || $ip1n == 127 || $ip1n >= $self->{b_idx_len}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not $ip1n or $ip1n == 10 or $ip1n == 127 or $ip1n >= $self->{"b_idx_len"}
not $ip1n or $ip1n == 10 or $ip1n == 127
not $ip1n or $ip1n == 10
MC/DC0%0/4
not $ip1n or $ip1n == 10 or $ip1n == 127 or $ip1n >= $self->{"b_idx_len"}
not $ip1n
$ip1n == 10
$ip1n == 127
$ip1n >= $self->{"b_idx_len"}
Truth table20%1/5
not(A) or B or C or D
A= not $ip1nB= $ip1n == 10C= $ip1n == 127D= $ip1n >= $self->{"b_idx_len"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | my $ipn = ip2long( $ip ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | $ipn = pack( 'N', $ipn ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | my @blocks = unpack "NN", substr( $self->{b_idx_str} , ( $ip1n - 1 ) * 4, 8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | my $min; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | my $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | ▶ | if ( $blocks[1] - $blocks[0] > $self->{range} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | my $part = $self->search_idx( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | $ipn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | floor( $blocks[0] / $self->{'range'} ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | floor( $blocks[1] / $self->{'range'} ) - 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | ▶ | $min = $part > 0 ? $part * $self->{range} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | $max = $part > $self->{m_idx_len} ? $self->{db_items} : ( $part + 1 ) * $self->{range}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | $min = $blocks[0] if $min < $blocks[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | $max = $blocks[1] if $max > $blocks[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $min = $blocks[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $max = $blocks[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | my $len = $max - $min; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | open( my $fl, $self->{ 'db_file' } ) || croak( 'Could not open db file' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | binmode $fl, ':bytes'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | seek $fl, $self->{db_begin} + $min * $self->{block_len}, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | read $fl, my $buf, $len * $self->{block_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | close $fl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | return $self->search_db( $buf, $ipn, 0, $len - 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub search_idx { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_idx: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | my $ipn = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | my $max = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | my $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | while ( $max - $min > 8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | $offset = ( $min + $max ) >> 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | if ( encode_utf8($ipn) gt encode_utf8( substr( ( $self->{m_idx_str} ), $offset * 4, 4 ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | $min = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $max = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | while ( encode_utf8($ipn) gt encode_utf8( substr( $self->{m_idx_str}, $min * 4, 4 ) ) && $min++ < $max ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&encode_utf8($ipn) gt &encode_utf8(substr($self->{"m_idx_str"}, $min * 4, 4)) and $min++ < $max
MC/DC50%1/2
&encode_utf8($ipn) gt &encode_utf8(substr($self->{"m_idx_str"}, $min * 4, 4)) and $min++ < $max
&encode_utf8($ipn) gt &encode_utf8(substr($self->{"m_idx_str"}, $min * 4, 4))
$min++ < $max
Truth table66%2/3
A and B
A= &encode_utf8($ipn) gt &encode_utf8(substr($self->{"m_idx_str"}, $min * 4, 4))B= $min++ < $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | return $min; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub search_db { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_db: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | my $ipn = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | my $max = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | if( $max - $min > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | $ipn = substr( $ipn, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | my $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | ▶ | while ( $max - $min > 8 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 18 | $offset = ( $min + $max ) >> 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 18 | ▶ | if ( encode_utf8( $ipn ) gt encode_utf8( substr( $str, $offset * $self->{block_len}, 3 ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 9 | $min = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | $max = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | while ( encode_utf8( $ipn ) ge encode_utf8( substr( $str, $min * $self->{block_len}, 3 ) ) && $min++ < $max ){} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&encode_utf8($ipn) ge &encode_utf8(substr($str, $min * $self->{"block_len"}, 3)) and $min++ < $max
MC/DC50%1/2
&encode_utf8($ipn) ge &encode_utf8(substr($str, $min * $self->{"block_len"}, 3)) and $min++ < $max
&encode_utf8($ipn) ge &encode_utf8(substr($str, $min * $self->{"block_len"}, 3))
$min++ < $max
Truth table66%2/3
A and B
A= &encode_utf8($ipn) ge &encode_utf8(substr($str, $min * $self->{"block_len"}, 3))B= $min++ < $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return hex( bin2hex( substr( $str, $min * $self->{block_len} + 3 , 3 ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | return hex( bin2hex( substr( $str, $min * $self->{block_len} - $self->{id_len}, $self->{id_len} ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | sub bin2hex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | my $str = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bin2hex: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | my $res = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | for my $i ( 0 .. length( $str ) - 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 9 | $res .= sprintf( '%02s', sprintf( '%x', ord( substr( $str, $i, 1 ) ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | sub ip2long { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | ▶ | return unpack( 'l*', pack( 'l*', unpack( 'N*', inet_aton( shift ) ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip2long: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub parse_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | ▶ | my __PACKAGE__ $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_info: called CC=5 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | my $seek = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my $info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | if ( $seek < $self->{country_size} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | open( my $fl, $self->{db_file} ) || croak('Could not open db file'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | binmode $fl, ':bytes'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | seek $fl, $seek + $self->{cities_begin}, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | read $fl, my $buf, $self->{max_country}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | close $fl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $info = extended_unpack( $self->{pack}[0], $buf ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ▶ | open( my $fl, $self->{db_file} ) || croak('Could not open db file'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | binmode $fl, ':bytes'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 3 | seek $fl, $seek + $self->{cities_begin}, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | read $fl, my $buf, $self->{max_city}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 3 | close $fl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | $info = extended_unpack( $self->{pack}[2], $buf ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | ▶ | if ($info) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | return $info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | sub extended_unpack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | my $flags = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extended_unpack: called CC=27 SCAR=41.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | my $result = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | my @flags_arr = split '/', $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | foreach my $flag_str ( @flags_arr ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 21 | my ( $type, $name ) = split ':', $flag_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 21 | my $flag = substr $type, 0, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 21 | my $num = substr $type, 1, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 21 | my $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 21 | ▶ | if ( $flag eq 't' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | elsif ( $flag eq 'T' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | $len = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | elsif ( $flag eq 's' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | elsif ( $flag eq 'n' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $len = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | elsif ( $flag eq 'S' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $len = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | elsif ( $flag eq 'm' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | elsif ( $flag eq 'M' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 6 | $len = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | elsif ( $flag eq 'd' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $len = 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | elsif ( $flag eq 'c' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $len = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | elsif ( $flag eq 'b' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | $len = index( $val, "\0", $pos ) - $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | $len = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 21 | my $subval = substr( $val, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 21 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 21 | ▶ | if ( $flag eq 't' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 14 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $res = ( unpack 'c', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | elsif ( $flag eq 'T' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | $res = ( unpack 'C', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | elsif ( $flag eq 's' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $res = ( unpack 's', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif ( $flag eq 'S' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $res = ( unpack 'S', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | elsif ( $flag eq 'm' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $res = ( unpack 'l', $subval . ( ord( substr( $subval, 2, 1 ) ) >> 7 ? "\xff" : "\0" ) )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | elsif ( $flag eq 'M' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 6 | $res = ( unpack 'L', $subval . "\0" )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | elsif ( $flag eq 'i' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $res = ( unpack 'l', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | elsif ( $flag eq 'I' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $res = ( unpack 'L', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | elsif ( $flag eq 'f' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $res = ( unpack 'f', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif ( $flag eq 'd' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $res = ( unpack 'd', $subval )[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | elsif ( $flag eq 'n' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $res = ( unpack 's', $subval )[0] / ( 10 ** $num ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | elsif ( $flag eq 'N' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 6 | $res = ( unpack 'l', $subval )[0] / ( 10 ** $num ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | elsif ( $flag eq 'c' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $res = rtrim $subval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | elsif ( $flag eq 'b' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 6 | $res = $subval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | $len++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 21 | $pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 21 | push @$result, $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | Geo::SypexGeo - API to detect cities by IP thru Sypex Geo database v.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | use Geo::SypexGeo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | my $geo = Geo::SypexGeo->new( './SxGeoCity.dat' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # Method parse return Geo::SypexGeo::Info object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | $info = $geo->parse( '87.250.250.203', 'en' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | or die "Cant parse 87.250.250.203"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | say $info->city(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | $info = $geo->parse('93.191.14.81') or die "Cant parse 93.191.14.81"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | say $info->city(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | say $info->country(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | my ( $latitude, $longitude ) = $info->coordinates(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | say "Latitude: $latitude Longitude: $longitude"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ## deprecated method (will be removed in future versions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | say $geo->get_city( '87.250.250.203', 'en' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | ## deprecated method (will be removed in future versions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | say $geo->get_city('93.191.14.81'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | ## deprecated method (will be removed in future versions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | say $geo->get_country('93.191.14.81'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | L<Sypex Geo|http://sypexgeo.net/> is a database to detect cities by IP. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | The database of IPs is included into distribution, but it is better to download latest version at L<download page|http://sypexgeo.net/ru/download/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | The database is availible with a names of the cities in Russian and English languages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | This module now is detect only city name and don't use any features to speed up of detection. In the future I plan to add more functionality. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | =head1 SOURCE AVAILABILITY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | The source code for this module is available from Github | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | at https://github.com/kak-tus/Geo-SypexGeo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | Andrey Kuzmin, E<lt>kak-tus@mail.ruE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =head1 CREDITS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | vrag86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | Copyright (C) 2014 by Andrey Kuzmin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||