1package MaxMind::DB::Reader::XS; 2 3use strict; 4use warnings; 5use namespace::autoclean; 6 7our $VERSION = '1.000008'; 8 9use 5.010000; 10 11# We depend on these in the C/XS code. 12use Math::Int64 (); 13use Math::Int128 (); 14 15use MaxMind::DB::Metadata 0.040001; 16use MaxMind::DB::Types qw( Int Str ); 17 18use Moo; 19 20with 'MaxMind::DB::Reader::Role::HasMetadata'; 21 22use XSLoader; 23 24## no critic (Subroutines::ProhibitCallsToUnexportedSubs) 25XSLoader::load( __PACKAGE__, $VERSION ); 26## use critic 27 28has file => ( 29 is => 'ro', 30 isa => Str, 31 coerce => sub { "$_[0]" }, 32 required => 1, 33); 34 35has _mmdb => ( 36 is => 'ro', 37 init_arg => undef, 38 lazy => 1, 39 builder => '_build_mmdb', 40 predicate => '_has_mmdb', 41); 42 43# XXX - making this private & hard coding this is obviously wrong - eventually 44# we need to expose the flag constants in Perl 45has _flags => ( 46 is => 'ro', 47 isa => Int, 48 init_arg => undef, 49 default => 0, 50); 51 52sub BUILD { $_[0]->_mmdb } 53 54## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) 55sub record_for_address { 56 return $_[0]->__data_for_address( $_[0]->_mmdb, $_[1] ); 57} 58 59sub iterate_search_tree { 60 my $self = shift; 61 my $data_callback = shift; 62 my $node_callback = shift; 63 64 return $self->_iterate_search_tree( 65 $self->_mmdb, $data_callback, 66 $node_callback 67 ); 68} 69 70sub _build_mmdb { 71 my $self = shift; 72 73 return $self->_open_mmdb( $self->file, $self->_flags ); 74} 75 76sub _build_metadata { 77 my $self = shift; 78 79 my $raw = $self->_raw_metadata( $self->_mmdb ); 80 81 my $metadata = MaxMind::DB::Metadata->new($raw); 82 83 return $metadata unless $ENV{MAXMIND_DB_READER_DEBUG}; 84 85 $metadata->debug_dump; 86 87 return $metadata; 88} 89 90## use critic 91 92sub DEMOLISH { 93 my $self = shift; 94 95 $self->_close_mmdb( $self->_mmdb ) 96 if $self->_has_mmdb; 97 98 return; 99} 100 101__PACKAGE__->meta->make_immutable; 102 1031; 104 105# ABSTRACT: Fast XS implementation of MaxMind DB reader 106 107__END__ 108 109=pod 110 111=encoding UTF-8 112 113=head1 NAME 114 115MaxMind::DB::Reader::XS - Fast XS implementation of MaxMind DB reader 116 117=head1 VERSION 118 119version 1.000008 120 121=head1 SYNOPSIS 122 123 my $reader = MaxMind::DB::Reader->new( file => 'path/to/database.mmdb' ); 124 125 my $record = $reader->record_for_address('1.2.3.4'); 126 127=head1 DESCRIPTION 128 129Simply installing this module causes L<MaxMind::DB::Reader> to use the XS 130implementation, which is much faster than the Perl implementation. 131 132The XS implementation links against the 133L<libmaxminddb|http://maxmind.github.io/libmaxminddb/> library. 134 135See L<MaxMind::DB::Reader> for API details. 136 137=for Pod::Coverage BUILD DEMOLISH 138 139=for :stopwords PPA 140 141=head1 VERSIONING POLICY 142 143This module uses semantic versioning as described by 144L<http://semver.org/>. Version numbers can be read as X.YYYZZZ, where X is the 145major number, YYY is the minor number, and ZZZ is the patch number. 146 147=head1 MAC OS X SUPPORT 148 149If you're running into install errors under Mac OS X, you may need to force a 150build of the 64 bit binary. For example, if you're installing via C<cpanm>: 151 152 ARCHFLAGS="-arch x86_64" cpanm MaxMind::DB::Reader::XS 153 154=head1 UBUNTU SUPPORT 155 156The version of libmaxminddb that is available by default with Ubuntu may be 157too old for this level of MaxMind::DB::Reader::XS. However, we do maintain a 158Launchpad PPA for all supported levels of Ubuntu. 159 160 https://launchpad.net/~maxmind/+archive/ubuntu/ppa 161 162Please visit the PPA page for more information, or, to configure your system, 163run as root: 164 165 # apt-add-repository ppa:maxmind/ppa 166 # apt-get update 167 168The PPA is now configured, and you may install (or upgrade) the libmaxminddb 169library via the usual apt commands. 170 171=head1 SUPPORT 172 173This module is deprecated and will only receive fixes for major bugs and 174security vulnerabilities. New features and functionality will not be added. 175 176Please report all issues with this code using the GitHub issue tracker at 177L<https://github.com/maxmind/MaxMind-DB-Reader-XS/issues>. 178 179Bugs may be submitted through L<https://github.com/maxmind/MaxMind-DB-Reader-XS/issues>. 180 181=head1 AUTHORS 182 183=over 4 184 185=item * 186 187Boris Zentner <bzentner@maxmind.com> 188 189=item * 190 191Dave Rolsky <drolsky@maxmind.com> 192 193=item * 194 195Ran Eilam <reilam@maxmind.com> 196 197=back 198 199=head1 CONTRIBUTORS 200 201=for stopwords Andy Jack Chris Weyl Florian Ragwitz Greg Oschwald Hidenori Sugiyama Mark Fowler Olaf Alders 202 203=over 4 204 205=item * 206 207Andy Jack <github@veracity.ca> 208 209=item * 210 211Chris Weyl <cweyl@alumni.drew.edu> 212 213=item * 214 215Florian Ragwitz <rafl@debian.org> 216 217=item * 218 219Greg Oschwald <goschwald@maxmind.com> 220 221=item * 222 223Hidenori Sugiyama <madogiwa@gmail.com> 224 225=item * 226 227Mark Fowler <mark@twoshortplanks.com> 228 229=item * 230 231Olaf Alders <oalders@maxmind.com> 232 233=back 234 235=head1 COPYRIGHT AND LICENSE 236 237This software is Copyright (c) 2013 - 2019 by MaxMind, Inc. 238 239This is free software, licensed under: 240 241 The Artistic License 2.0 (GPL Compatible) 242 243=cut 244