| Tie-Hash-Cannabinol documentation | Contained in the Tie-Hash-Cannabinol distribution. |
Tie::Hash::Cannabinol - Perl extension for creating hashes that forget things
use Tie::Hash::Cannabinol; my %hash; tie %hash, 'Tie::Hash::Cannabinol';
or
my %hash : Stoned; # % hash can now be treated exactly like a normal hash - but don't trust # anything it tells you.
Tie::Hash::Cannabinol is a completely useless demonstration of how to use
Tie::StdHash to pervert the behaviour of Perl hashes. Once a hash has been
tied to Tie::Hash::Cannabinol, there is a 25% chance that it will forget
anything that you tell it immediately and a further 25% chance that it
won't be able to retrieve any information you ask it for. Any information
that it does return will be pulled at random from its keys.
Oh, and the return value from exists isn't to be trusted either :)
Stores data in the hash 3 times out of 4.
Fetchs something from the hash 3 times out of 4.
Gives very dodgy information about the existance of keys in the hash.
Dave Cross <dave@mag-sol.com>
The latest version of this module will always be available from http://code.mag-sol.com/Tie-Hash-Cannabinol or from CPAN at http://search.cpan.org/dist/Tie-Hash-Cannabinol/.
Copyright (C) 2001-8, Magnum Solutions Ltd. All Rights Reserved.
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl(1), perltie(1), Tie::StdHash(1)
| Tie-Hash-Cannabinol documentation | Contained in the Tie-Hash-Cannabinol distribution. |
# $Id: Cannabinol.pm 28 2008-03-08 12:01:49Z dave $
package Tie::Hash::Cannabinol; use 5.006; use strict; use warnings; use vars qw($VERSION @ISA); use Tie::Hash; use Attribute::Handlers autotie => { "__CALLER__::Stoned" => __PACKAGE__ }; $VERSION = sprintf "%d", '$Revision: 28 $ ' =~ /(\d+)/; @ISA = qw(Tie::StdHash);
sub STORE { my ($self, $key, $val) = @_; return if rand > .75; $self->{$key} = $val; }
sub FETCH { my ($self, $key) = @_; return if rand > .75; return $self->{(keys %$self)[rand keys %$self]}; }
sub EXISTS { return rand > .5; } 1; __END__