Skip to content
Permalink
Browse files
Allowed Geo::IP as well as Geo::IP::PurePerl; Un-hardcoded the GeoIP.…
…dat location;

Not sure if it's the best way of achieving this, but I think it works...
  • Loading branch information
jesusbagpuss committed Dec 5, 2013
1 parent ce7b4cf commit cdeb3281694ff1eee3d4f97660560aa4ef3cd30c
Showing with 25 additions and 11 deletions.
  1. +25 −11 cfg/plugins/EPrints/Plugin/Stats/Processor/Access/Country.pm
@@ -7,31 +7,45 @@ use strict;
# Processor::Access::Country
#
# Processes the Country codes from Access records. Provides the 'eprint_countries' datatype
# Note that this requires Geo::IP to work.
# Note that this requires Geo::IP or Geo::IP::PurePerl to work.
#
# From: http://search.cpan.org/~borisz/Geo-IP-PurePerl-1.25/lib/Geo/IP/PurePerl.pm#SEE_ALSO
# Geo::IP - this now has the PurePerl code merged it, so it supports both XS and Pure Perl
# implementations. The XS implementation is a wrapper around the GeoIP C API, which is much
# faster than the Pure Perl API.
# I think this has been in place since ~Aug 2008

sub new
{
my( $class, %params ) = @_;
my $self = $class->SUPER::new( %params );

unless( EPrints::Utils::require_if_exists( "Geo::IP::PurePerl" ) )
{
$self->{advertise} = 0;
$self->{disable} = 1;
$self->{error} = "Failed to load required module for Processor::Access::Country. Country information will not be available.";
return $self;
#Test Geo::IP first - it's faster!
my $geoPackage = "Geo::IP";

if( !EPrints::Utils::require_if_exists( $geoPackage ) ){
# no Geo::IP, try Geo::IP::PurePerl
$geoPackage = "Geo::IP::PurePerl";
unless( EPrints::Utils::require_if_exists( $geoPackage ) )
{
$self->{advertise} = 0;
$self->{disable} = 1;
$self->{error} = "Failed to load required module for Processor::Access::Country. Country information will not be available.";
return $self;
}
}

if( -e '/opt/eprints3/lib/geoip/GeoIP.dat' )

my $geoipDatFile = $self->{session}->config( "lib_path").'/geoip/GeoIP.dat';

if( -e $geoipDatFile )
{
# if possible, use the GeoIP data shipped with EPrints
$self->{geoip} = Geo::IP::PurePerl->new( '/opt/eprints3/lib/geoip/GeoIP.dat' );
$self->{geoip} = $geoPackage->new( $geoipDatFile );
}
else
{
# otherwise use the global file
$self->{geoip} = Geo::IP::PurePerl->new( 1 );
$self->{geoip} = $geoPackage->new( 1 );
}

unless( defined $self->{geoip} )

0 comments on commit cdeb328

Please sign in to comment.