NAME
Class::PseudoHash - Emulates Pseudo-Hash behaviour via overload
SYNOPSIS
use Class::PseudoHash;
my @arg = ([qw/key1 key2 key3 key4/], [1..10]);
$ref = fields::phash(@arg); # phash override
$ref = Class::PseudoHash->new(@arg); # 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. The fields
pragma will change to use a different implementation.
Although "Pseudo-hashes: Using an array as a hash" in perlref recommends against using the first-element-as-index behaviour, it's doubtless that many brave souls still wrote codes that utilized it, and fears that the elimination of pseudo-hashes will require a massive rewrite of their code.
As one of the primary victims, I tried to find a drop-in solution that could emulate exactly the same semantic of pseudo-hashes, thus keeping all my legacy code intact. So Class::PseudoHash
is born.
Hence, if you're using the perferred 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 nonexistent hash key, then a new pseudohash 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.
CAVEATS
Compile-type validating of keys is not possible with this module, for obvious reasons. Also, the performance will not be as fast as typed pseudohashes (but generally faster than untyped ones).
Perl versions prior to v5.6.0 has a bug that prevents proper overloading for stringification, so a placeholder of Class::PseudoHash=ARRAY(0xbadfeed)
is always used.
SEE ALSO
fields, "Pseudo-hashes: Using an array as a hash" in perlref
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
Copyright 2001 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.