Tie::StrictHash

Tie::StrictHash is a hash with 'strict'-like semantics.
Download

Tie::StrictHash Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Kevin Michael Vail
  • Publisher web site:
  • http://search.cpan.org/~kvail/Tie-StrictHash-1.0/StrictHash.pm

Tie::StrictHash Tags


Tie::StrictHash Description

Tie::StrictHash is a hash with 'strict'-like semantics. Tie::StrictHash is a hash with 'strict'-like semantics.SYNOPSISuse Tie::StrictHash;strict_hash %hash, key => value, ...;$hashctl = tie %hash, 'Tie::StrictHash', key => value , ...;$hashctl->add(key => value, ...);@values = $hashctl->delete(key, ...);$hashctl->clear;Tie::StrictHash is a module for implementing some of the same semantics for hash members that 'use strict' gives to variables. The following constraints are applied to a strict hash:oNo new keys may be added to the hash except through the add method of the hash control object.oNo keys may be deleted except through the delete method of the hash control object.oThe hash cannot be re-initialized (cleared) except through the clear method of the hash control object.oAttempting to retrieve the value for a key that doesn't exist is a fatal error.oAttempting to store a value for a key that doesn't exist is a fatal error.In order to make any changes or modifications to the hash, you must either keep the return value from strict_hash (or tie) or retrieve it by using tied %hash. Think of it as the "key" that "unlocks" the hash so that you can make changes to it.The original reason for writing this module was for classes that implement an object as a hash, using hash members as instance variables. It's all too easy to use the wrong member name, with the same results as misspelling a variable name when use strict isn't in effect.Note that just as use strict allows you to create new variables by either specifying an explicit package name or by using use vars, a strict hash allows you to create or delete members by using the appropriate methods. However, it does prevent you from creating or deleting members accidentally. This is in keeping with the general philosophy of Perl.If you import the pseudo-symbol warn, Tie::StrictHash will only issue warning messages rather than dying when an attempt is made to reference a hash value that doesn't exist.If you import the pseudo-symbol confess, either by itself or along with warn, you'll get a stack backtrace as well when something happens. Requirements: · Perl


Tie::StrictHash Related Software