1 package PLP::Tie::Delay;
8 Delays hash generation. Unties the hash on first access, and replaces it by the generated one.
9 Uses symbolic references, because circular ties make Perl go nuts :)
11 tie %Some::hash, 'PLP::Tie::Delay', 'Some::hash', sub { \%generated_hash };
13 This module is part of the PLP internals and probably not of any use to others.
19 untie %{ $self->[0] };
20 %{ $self->[0] } = %{ $self->[1]->() };
24 my ($class, $hash, $source) = @_;
25 return bless [ $hash, $source ], $class;
29 my ($self, $key) = @_;
31 return ${ $self->[0] }{$key};
35 my ($self, $key, $value) = @_;
37 return ${ $self->[0] }{$key} = $value;
41 my ($self, $key) = @_;
43 return delete ${ $self->[0] }{$key};
49 return %{ $self->[0] };
53 my ($self, $key) = @_;
55 return exists ${ $self->[0] }{$key};
66 # Let's hope this never happens. (It's shouldn't.)