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

NAME

Data::Hopen::Scope::Hash - a hash-based nested key-value store

SYNOPSIS

This class implements Data::Hopen::Scope using a single hash table as the storage. It only supports one set of data ("$set" in Data::Hopen::Scope), which is named 0.

ATTRIBUTES

outer

The fallback Scope for looking up names not found in this Scope. If non is provided, it is undef, and no fallback will happen.

name

Not used, but provided so you can use "hnew" in Data::Hopen to make Scopes.

METHODS

See also "add", below, which is part of the public API.

Several of the functions receive a $levels parameter. Its meaning is:

  • If $levels is provided and nonzero, go up that many more levels (i.e., $levels==0 means only return this scope's local names).

  • If $levels is not provided or not defined, go all the way to the outermost Scope.

FUNCTIONS TO BE OVERRIDDEN IN SUBCLASSES

To implement a Scope with a different data-storage model than the hash this class uses, subclass Scope and override these functions. Only "add" is part of the public API.

add

Add key-value pairs to this scope. Returns the scope so you can chain. Example usage:

    my $scope = Data::Hopen::Scope::Hash->new()->add(foo => 1);

add is responsible for handling any conflicts that may occur. In this particular implementation, the last-added value for a particular key wins.

TODO add $set option

adopt_hash

Takes over the given hash to be the new contents of the Scope::Hash. Usage example:

    $scope->adopt_hash({ foo => 42 });

The scope uses exactly the hash passed, not a clone of it. If this is not applicable to a subclass, that subclass should override it as ... or an express die.

_names_here

Populates a Set::Scalar with the names of the items stored in this Scope, but not any outer Scope. Called as:

    $scope->_names_here($retval[, $set]);

No return value.

_find_here

Looks for a given item in this scope, but not any outer scope. Called as:

    $scope->_find_here($name[, $set])

Returns the value, or undef if not found.