NAME

Geo::Location::IP::Database::SimpleReader - Read MaxMind DB files

VERSION

version 0.002

SYNOPSIS

use Geo::Location::IP::Database::SimpleReader;
my $reader = Geo::Location::IP::Database::SimpleReader->new(
  file    => '/path/to/City.mmdb',
  locales => ['de', 'en'],
);
my $ip = '1.2.3.4';
my $city_model = $reader->city(ip => $ip)
  or die "No record found for IP address $ip";
my $city    = $city_model->city;
my $country = $city_model->country;
printf "%s in %s\n", $city->name, $country->name;

DESCRIPTION

Read MaxMind DB files and map IP addresses to location information such as country and city names.

The query methods return the undefined value on unsuccessful queries. Use Geo::Location::IP::Database::Reader if you prefer exceptions.

SUBROUTINES/METHODS

new

my $reader = Geo::Location::IP::Database::SimpleReader->new(
    file    => '/path/to/City.mmdb',
    locales => ['de', 'en'],
);

Returns a new reader object. Dies if the specified file cannot be read.

The file parameter is a path to a database in the MaxMind DB file format.

The locales parameter is an array reference of acceptable locales in preferred order. The default is ['en']. It is recommended to always append 'en' to your list, as English may be the only language in the database. Common locale codes are:

  • de - German

  • en - English

  • es - Spanish

  • fa - Farsi

  • fr - French

  • ja - Japanese

  • ko - Korean

  • pt-BR - Brazilian Portuguese

  • ru - Russian

  • zh-CN - Simplified Chinese

file

my $file = $reader->file;

Returns the file path passed to the constructor.

locales

my @locales = @{$reader->locales};

Returns the locale codes passed to the constructor.

metadata

my $metadata = $reader->metadata;

Returns an IP::Geolocation::MMDB::Metadata object containing information about the database.

anonymous_ip

my $anon_ip_model = $reader->anonymous_ip(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::AnonymousIP object or the undefined value. Dies if the address is not a valid IP address.

asn

my $asn_model = $reader->asn(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::ASN object or the undefined value. Dies if the address is not a valid IP address.

city

my $city_model = $reader->city(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::City object or the undefined value. Dies if the address is not a valid IP address.

connection_type

my $ct_model = $reader->connection_type(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::ConnectionType object or the undefined value. Dies if the address is not a valid IP address.

country

my $country_model = $reader->country(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::Country object or the undefined value. Dies if the address is not a valid IP address.

domain

my $domain_model = $reader->domain(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::Domain object or the undefined value. Dies if the address is not a valid IP address.

enterprise

my $enterprise_model = $reader->enterprise(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::Enterprise object or the undefined value. Dies if the address is not a valid IP address.

isp

my $isp_model = $reader->isp(ip => '1.2.3.4');

Takes an IP address as a string and returns a Geo::Location::IP::Model::ISP object or the undefined value. Dies if the address is not a valid IP address.

DIAGNOSTICS

See IP::Geolocation::MMDB.

CONFIGURATION AND ENVIRONMENT

None.

DEPENDENCIES

Requires the module IP::Geolocation::MMDB.

Requires databases in the MaxMind DB file format from MaxMind or DP-IP.com.

INCOMPATIBILITIES

None.

BUGS AND LIMITATIONS

None known.

AUTHOR

Andreas Vögele <voegelas@cpan.org>

LICENSE AND COPYRIGHT

Copyright (C) 2025 Andreas Vögele

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.