Mojolicious::Plugin::Geolocation::MMDB - Look up location information by IP address
version 1.000
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;
This Mojolicious plugin provides a helper that maps IPv4 and IPv6 addresses to location information such as country and city names.
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.
$plugin->register(Mojolicious->new, {file => 'City.mmdb'});
Registers the plugin in a Mojolicious application. The "file" parameter is required.
The plugin was loaded without a database filename.
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.
MOJO_REVERSE_PROXY
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.
None.
None known.
Andreas Vögele <voegelas@cpan.org>
Copyright (C) 2022 Andreas Vögele
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mojolicious::Plugin::Geolocation::MMDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Geolocation::MMDB
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Geolocation::MMDB
For more information on module installation, please visit the detailed CPAN module installation guide.