Hash::Util::FieldHash::Compat - Use L<Hash::Util::FieldHash> or ties, depending


Hash-Util-FieldHash-Compat documentation Contained in the Hash-Util-FieldHash-Compat distribution.

Index


Code Index:

NAME

Top

Hash::Util::FieldHash::Compat - Use Hash::Util::FieldHash or ties, depending on availability.

SYNOPSIS

Top

	use Hash::Util::FieldHash::Compat;

	# pretend you are using L<Hash::Util::FieldHash>
	# under older perls it'll be Tie::RefHash::Weak instead (slower, but same behavior)

DESCRIPTION

Top

Under older perls this module provides a drop in compatible api to Hash::Util::FieldHash using perltie. When Hash::Util::FieldHash is available it will use that instead.

This way code requiring field hashes can benefit from fast, robust field hashes on Perl 5.10 and newer, but still run on older perls that don't ship with that module.

See Hash::Util::FieldHash for all the details of the API.

SEE ALSO

Top

Hash::Util::FieldHash, Tie::RefHash, Tie::RefHash::Weak.

VERSION CONTROL

Top

This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.

AUTHOR

Top

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Top


Hash-Util-FieldHash-Compat documentation Contained in the Hash-Util-FieldHash-Compat distribution.

#!/usr/bin/perl

package Hash::Util::FieldHash::Compat;

use strict;
use warnings;

use constant REAL_FIELDHASH => do { local $@; eval { require Hash::Util::FieldHash } };

BEGIN {
	if ( REAL_FIELDHASH ) {
		require Hash::Util::FieldHash;
		Hash::Util::FieldHash->import(":all");
	} else {
		require Hash::Util::FieldHash::Compat::Heavy;
	}
}

our $VERSION = "0.03";

sub import {
	if ( REAL_FIELDHASH ) {
		my $class = "Hash::Util::FieldHash";

		shift @_;
		unshift @_, $class;

		goto $class->can("import");
	} else {
		my $class = shift;
		$class->export_to_level(1, $class, @_);
	}
}

__PACKAGE__

__END__