NAME

Hash::FieldHash - A lightweight field hash implementation

VERSION

This document describes Hash::FieldHash version 0.04.

SYNOPSIS

use Hash::FieldHash qw(:all);

fieldhash my %foo;

fieldhashes \my(%bar, %baz);

{
	my $o = Something->new();

	$foo{$o} = 42;

	print $foo{$o}; # => 42
}

# now %foo is empty because $o is released

DESCRIPTION

Hash::FieldHash provides the field hash mechanism which supports the inside-out technique.

You may know Hash::Util::FieldHash. It's a very useful module, but too complex to understand all the functions and only available in 5.10. For pre-5.10, H::U::FieldHash::Compat is in CPAN, but it's too slow to use.

This is an alternative to H::U::F with new features:

Simple interface

Hash::FieldHash provides a few functions: fieldhash() and fieldhashes().

Availability in pre-5.10

Although Hash::FieldHash uses a new feature introduced in Perl 5.10, the uvar magic for hashes described in "GUTS" in Hash::Util::Fieldhash, it also supports Perl 5.8 using the traditional tie-hash layer.

High performance

Hash::FieldHash is faster than Hash::Util::FieldHash.

INTERFACE

Exportable functions

fieldhash(%hash)

Creates a field hash. The argument must be a hash.

Returns nothing.

fieldhashes(@hash_refs)

Creates a number of field hashes. All the arguments must be hash references.

Returns nothing.

FEATURES

Thread support

As Hash::Util::FieldHash does, Hash::FieldHash fully supports threading using the CLONE method.

Relic support

Available in pre-5.10.

NOTES

The type of field hash keys

Hash::FieldHash accepts only references and registered addresses as its keys, whereas Hash::Util::FieldHash accepts any scalars.

According to "The Generic Object" in Hash::Util::FieldHash, Non-reference keys in H::U::F are used for class fields. That is, all the fields defined by H::U::F act as both object fields and class fields by default. If you do not want them to be class fields, you must check the type of $self explicitly. In addition, these class fields are never inherited. This function of H::U::F seems erroneous, so Hash::FieldHash restricts the type of keys.

The ID of field hash keys

While Hash::Util::FieldHash uses refaddr as the IDs of field hash keys, Hash::FieldHash allocates arbitrary natural numbers as the IDs.

DEPENDENCIES

Perl 5.8.1 or later, and a C compiler.

BUGS

No bugs have been reported.

Please report any bugs or feature requests to the author.

SEE ALSO

Hash::Util::FieldHash.

Hash::Util::FieldHash::Compat.

"Magic Virtual Tables" in perlguts.

AUTHOR

Goro Fuji <gfuji(at)cpan.org>.

LICENSE AND COPYRIGHT

Copyright (c) 2009, Goro Fuji. Some rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.