☻ 唐鳳 ☺ > Class-PseudoHash-1.10 > Class::PseudoHash

Download:
Class-PseudoHash-1.10.tar.gz

Dependencies

Annotate this POD

Related Modules

Data::Dumper
Devel::Peek
Tie::IxHash
more...
By perlmonks.org
View/Report Bugs
Module Version: 1.10   Source  

NAME ^

Class::PseudoHash - Emulates Pseudo-Hash behaviour via overload

VERSION ^

This document describes version 1.10 of Class::PseudoHash, released October 14, 2007.

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 5.8.

As of Perl 5.10, pseudo-hashes have been removed from Perl, replaced by restricted hashes provided by Hash::Util. Additionally, Perl 5.10 no longer supports the fields::phash() API.

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 legacy codebase still depending on pseudohashes; elimination of pseudo-hashes would therefore require a massive rewrite of their programs.

Back in 2002, 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 instead:

    $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 ^

Audrey Tang <cpan@audreyt.org>

COPYRIGHT ^

Copyright 2001, 2002, 2007 by Audrey Tang <cpan@audreyt.org>.

This software is released under the MIT license cited below.

The "MIT" License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

syntax highlighting: