NAME
Class::PseudoHash - Emulates Pseudo-Hash behaviour via overload
VERSION
This document describes version 1.01 of Class::PseudoHash, released June 20, 2002
SYNOPSIS
use Class::PseudoHash;
my @args = ([qw/key1 key2 key3 key4/], [1 .. 10]);
my $ref1 = fields::phash(@args); # phash() override
my $ref2 = Class::PseudoHash->new(@args); # constructor syntax
DESCRIPTION
Due to its impact on overall performance of ordinary hashes, pseudo-hashes are deprecated in perl v5.8, and will cease to exist in perl v5.10. By then, the fields
pragma is supposed to change to use a different implementation.
Although "Pseudo-hashes: Using an array as a hash" in perlref recommends against depending on the underlying implementation (i.e. using the first array element as hash indice), there are undoubtly many brave souls still writing such code, and fearing that the elimination of pseudo-hashes will require a massive rewrite of their programs.
As one of the primary victims, I tried to devise a drop-in solution that could emulate exactly the same semantic of pseudo-hashes, thus keeping all my legacy code intact. So Class::PseudoHash
was born.
Hence, if your code use the preferred fields::phash()
function, just write:
use fields;
use Class::PseudoHash;
then everything will work like before. If you are creating pseudo-hashes by hand ([{}]
anyone?), just write this:
$ref = Class::PseudoHash->new;
and use the returned object in whatever way you like.
NOTES
If you set $Class::PseudoHash::FixedKeys
to a false value and tries to access a non-existent hash key, then a new pseudo-hash entry will be created silently. This is most useful if you're already using untyped pseudo-hashes, and don't want the compile-time checking feature.
Compile-time validating of keys is not possible with this module, for obvious reasons. Also, the performance will not be as fast as typed pseudo-hashes (but generally faster than untyped ones).
SEE ALSO
fields, "Pseudo-hashes: Using an array as a hash" in perlref
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
Copyright 2001, 2002 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.