NAME
Mojolicious::Plugin::Geolocation::MMDB - Look up location information by IP address
VERSION
version 0.002
SYNOPSIS
use Mojolicious::Lite -signatures;
plugin 'Geolocation::MMDB', {file => 'Country.mmdb'};
get '/' => sub ($c) {
my $location = $c->geolocation;
my $country =
eval { $location->{country}->{names}->{en} } // 'unknown location';
$c->render(text => "Welcome visitor from $country");
};
app->start;
DESCRIPTION
This Mojolicious plugin provides a helper that maps IPv4 and IPv6 addresses to location information such as country and city names.
HELPERS
geolocation
my $request_location = $c->geolocation;
my $arbitrary_location = $c->geolocation('1.2.3.4');
If no IP address is given, the location of the current transaction's remote address is looked up. Otherwise, the specified IP address is looked up. Returns the undefined value if no location information is available for the IP address. Dies if the address is not a valid IP address.
SUBROUTINES/METHODS
register
$plugin->register(Mojolicious->new, {file => 'City.mmdb'});
Registers the plugin in a Mojolicious application. The "file" parameter is required.
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
If your application is behind a reverse proxy, the environment variable MOJO_REVERSE_PROXY
needs to bet set. See Mojolicious::Guides::Cookbook for more information.
DEPENDENCIES
Requires the Perl modules Mojolicious and IP::Geolocation::MMDB from CPAN.
Requires an IP to country, city or ASN database in the MaxMind DB file format from MaxMind or DP-IP.com.
INCOMPATIBILITIES
None.
AUTHOR
Andreas Vögele <voegelas@cpan.org>
BUGS AND LIMITATIONS
None known.
LICENSE AND COPYRIGHT
Copyright 2022 Andreas Vögele
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.