Class::PseudoHash - Emulates Pseudo-Hash behaviour via overload
This document describes version 1.01 of Class::PseudoHash, released June 20, 2002
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
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.
fields
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.
Class::PseudoHash
Hence, if your code use the preferred fields::phash() function, just write:
fields::phash()
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.
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.
$Class::PseudoHash::FixedKeys
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).
fields, "Pseudo-hashes: Using an array as a hash" in perlref
Autrijus Tang <autrijus@autrijus.org>
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.
See http://www.perl.com/perl/misc/Artistic.html
To install Class::PseudoHash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::PseudoHash
CPAN shell
perl -MCPAN -e shell install Class::PseudoHash
For more information on module installation, please visit the detailed CPAN module installation guide.