package Net::IP::Match::Trie;

use strict;
use warnings;
use 5.008_005;

our $VERSION = '1.00';

sub import {
    my $class = shift;

    $ENV{NIMT_PP} = grep {$_ eq "PP"} @_ unless $ENV{NIMT_PP};

    unless ($ENV{NIMT_PP}) {
        eval { require Net::IP::Match::Trie::XS; };
    if ($@ || $ENV{NIMT_PP}) {
        require Net::IP::Match::Trie::PP;



=encoding utf-8

=begin html

<a href=""><img src="" alt="Build Status" /></a>
<a href=""><img src="" alt="Coverage Status" /></a>

=end html

=head1 NAME

Net::IP::Match::Trie - Efficiently match IP addresses against IP ranges with Trie (prefix tree)


  use Net::IP::Match::Trie;
  my $matcher = Net::IP::Match::Trie->new;
  $matcher->add(google => [qw(]);
  $matcher->add(yahoo  => [qw(]);
  $matcher->add(ask    => [qw(]);
  $matcher->add(docomo   => [qw( ...)]);
  $matcher->add(au       => [qw( ...)]);
  $matcher->add(softbank => [qw( ...)]);
  $matcher->add(willcom  => [qw(  ...)]);
  say $matcher->match_ip(""); # => "google"
  say $matcher->match_ip(""); # => "yahoo"
  say $matcher->match_ip("");   # => ""


Net::IP::Match::Trie is XS or Pure Perl implementation of matching IP address against Net ranges.

Net::IP::Match::Trie uses Trie (prefix tree) data structure, so very fast lookup time (match_ip) but slow setup (add) time.
This module is useful for once initialization and a bunch of lookups model such as long life server process.

=head1 METHODS

=over 4

=item B<add>(LABEL => CIDRS)

  LABEL: Str
  CIDRS: ArrayRef

register CIDRs to internal data tree labeled as "LABEL".

=item B<match_ip>(IP)

  IP: Str

return "LABEL" if IP matched registered CIDRs. otherwise return "".


=head1 AUTHOR

HIROSE Masaaki E<lt>hirose31@gmail.comE<gt>



  git clone git://

patches and collaborators are welcome.

=head1 SEE ALSO


Copyright HIROSE Masaaki

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.