The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::CIDR::Lookup::Tie

DESCRIPTION

This is a Tie::Hash interface to Net::CIDR::Lookup, see there for details.

The tied hash accepts net blocks as keys in the same syntax as Net::CIDR::Lookup's add() or add_range() and stores arbitrary (with the exception of undef) scalar values under these. The same coalescing as in Net::CIDR::Lookup takes place, so if you add any number of different keys you may end up with a hash containing less keys if any mergers took place.

Of course you can retrieve the corresponding net block's value for any key that is contained within that block, so the number of possible lookup keys is usually far greater than that of explicitly stored key/value pairs.

SYNOPSIS

  use Net::CIDR::Lookup::Tie;

  tie my %t, 'Net::CIDR::Lookup::Tie';
  $t{'192.168.42.0/24'}   = 1;    # Add first network
  $t{'192.168.43.0/24'}   = 1;    # Automatic coalescing to a /23
  $t{'192.168.41.0/24'}   = 2;    # Stays separate due to different value

  print $t{'192.168.42.100'};            # prints "1"

  foreach(keys %h) { ... }                       # Do anything you'd do with a regular hash

METHODS

STORE

Stores a value under a given key

FETCH

Fetches the value stored under a given key

FIRSTKEY

Gets the first key in the hash. Used for iteration with each()

NEXTKEY

Gets the next key from the hash. Used for iteration with each()

EXISTS

Tests if a key is in the hash. Also returns true for blocks or addresses contained within a block that was actually stored.

DELETE

Delete a key from the hash. Note that the same restrictions as for Net::CIDR::Lookup regarding netblock splitting apply!

CLEAR

Deletes all keys and their values.

SCALAR

Returns the number of keys in the hash

_updkeys

Private method to update the internal key cache used for iteration