X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHash%2FUtil.pm;h=3d65ee0b11604a3c5fa757242096a94bffd0c88c;hb=f1317c8d183c687b884dabebf7d01723441851a4;hp=0c8979d61b3c7f70fa2cb2de9950b9af5c0f6c96;hpb=a94e8023b124b822fcd2c4e28f8dc89b1f24e54a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Hash/Util.pm b/lib/Hash/Util.pm index 0c8979d..3d65ee0 100644 --- a/lib/Hash/Util.pm +++ b/lib/Hash/Util.pm @@ -7,9 +7,9 @@ use Carp; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(lock_keys unlock_keys lock_value unlock_value - lock_hash unlock_hash + lock_hash unlock_hash hash_seed ); -our $VERSION = 0.04; +our $VERSION = 0.05; =head1 NAME @@ -19,7 +19,8 @@ Hash::Util - A selection of general-utility hash subroutines use Hash::Util qw(lock_keys unlock_keys lock_value unlock_value - lock_hash unlock_hash); + lock_hash unlock_hash + hash_seed); %hash = (foo => 42, bar => 23); lock_keys(%hash); @@ -32,6 +33,8 @@ Hash::Util - A selection of general-utility hash subroutines lock_hash (%hash); unlock_hash(%hash); + my $hashes_are_randomised = hash_seed() != 0; + =head1 DESCRIPTION C contains special functions for manipulating hashes that @@ -59,10 +62,11 @@ This is intended to largely replace the deprecated pseudo-hashes. Restricts the given %hash's set of keys to @keys. If @keys is not given it restricts it to its current keyset. No more keys can be -added. delete() and exists() will still work, but it does not effect -the set of allowed keys. B: the current implementation does not -allow you to bless() the resulting hash, so if you want to use -lock_keys() for an object, you need to bless it prior to locking it. +added. delete() and exists() will still work, but will not alter +the set of allowed keys. B: the current implementation prevents +the hash from being bless()ed while it is in a locked state. Any attempt +to do so will raise an exception. Of course you can still bless() +the hash before you call lock_keys() so this shouldn't be a problem. unlock_keys(%hash); @@ -175,8 +179,37 @@ sub unlock_hash (\%) { } +=item B + + my $hash_seed = hash_seed(); + +hash_seed() returns the seed number used to randomise hash ordering. +Zero means the "traditional" random hash ordering, non-zero means the +new even more random hash ordering introduced in Perl 5.8.1. + +B: by knowing it one +can craft a denial-of-service attack against Perl code, even remotely, +see L for more information. +B to people who don't need to know it. +See also L. + +=cut + +sub hash_seed () { + Internals::rehash_seed(); +} + =back +=head1 CAVEATS + +Note that the trapping of the restricted operations is not atomic: +for example + + eval { %hash = (illegal_key => 1) } + +leaves the C<%hash> empty rather than with its original contents. + =head1 AUTHOR Michael G Schwern on top of code by Nick @@ -184,7 +217,8 @@ Ing-Simmons and Jeffrey Friedl. =head1 SEE ALSO -L, L, L +L, L, L, +and L. =cut