NAME

Geo::Location::IP::Model::City - Records associated with a city

VERSION

version 0.002

SYNOPSIS

use Geo::Location::IP::Database::Reader;
my $reader = Geo::Location::IP::Database::Reader->new(
  file    => '/path/to/City.mmdb',
  locales => ['de', 'en'],
);
eval {
  my $city_model = $reader->city(ip => '1.2.3.4');
  my $city       = $city_model->city;
  my $country    = $city_model->country;
  printf "%s in %s\n", $city->name, $country->name;
};

DESCRIPTION

This class contains records from an IP address query in a city database.

SUBROUTINES/METHODS

new

my $city_model = Geo::Location::IP::Model::City->new(
  raw => {
      city                => {names    => {en => 'Berlin'}},
      continent           => {names    => {en => 'Europe'}},
      country             => {names    => {en => 'Germany'}},
      location            => {latitude => 52.52, longitude => 13.41},
      maxmind             => {queries_remaining => 9999},
      registered_country  => {names    => {en => 'Germany'}},
      represented_country => {
        names => {en => 'United States'},
        type  => 'military',
      },
      subdivisions => [
        {names => {en => 'Berlin'}, iso_code => 'BE'},
      ],
      traits => {domain => 'example.com'},
  },
  ip_address => $ip_address,
  locales    => ['en'],
);

Creates a new object.

All records may contain undefined values.

city

my $city = $city_model->city;

Returns a Geo::Location::IP::Record::City object.

continent

my $continent = $city_model->continent;

Returns a Geo::Location::IP::Record::Continent object.

country

my $country = $city_model->country;

Returns a Geo::Location::IP::Record::Country object.

location

my $location = $city_model->location;

Returns a Geo::Location::IP::Record::Location object.

maxmind

my $maxmind = $city_model->maxmind;

Returns a Geo::Location::IP::Record::MaxMind object.

postal

my $postal = $city_model->posal;

Returns a Geo::Location::IP::Record::Postal object.

registered_country

my $country = $city_model->registered_country;

Returns a Geo::Location::IP::Record::Country object for the country where the ISP registered the network.

represented_country

my $country = $city_model->represented_country;

Returns a Geo::Location::IP::Record::RepresentedCountry for the country represented by the users of the IP address. For example, the country represented by an overseas military base.

subdivisions

my @subdivisions = $city_model->subdivisions;

Returns an array of Geo::Location::IP::Record::Subdivision objects. Examples of subdivisions are federal states, counties and provinces.

most_specific_subdivision

my $subdivision = $city_model->most_specific_subdivision;

Returns a single Geo::Location::IP::Record::Subdivision object. If there aren't any subdivisions, an object with undefined values is returned.

traits

my $traits = $city_model->traits;

Returns a Geo::Location::IP::Record::Traits object with various details about the queried IP address.

DIAGNOSTICS

None.

CONFIGURATION AND ENVIRONMENT

None.

DEPENDENCIES

None.

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.