1 package PLP::Tie::Delay;
11 Delays hash generation. Unties the hash on first access, and replaces it by the generated one.
12 Uses symbolic references, because circular ties make Perl go nuts :)
14 tie %Some::hash, 'PLP::Tie::Delay', 'Some::hash', sub { \%generated_hash };
16 This module is part of the PLP internals and probably not of any use to others.
24 my $code = delete $self->[1] or return;
25 $self->[0] = $code->();
29 untie %{ $self->[0] };
30 %{ $self->[0] } = %{ $self->[1]->() }; # *{ $self->[0] } = $self->[1]->();
35 # my ($class, $hash, $source) = @_;
36 return bless [ @_[1, 2] ], $_[0];
40 my ($self, $key) = @_;
42 return $self->[0]->{$key};
46 my ($self, $key, $value) = @_;
48 return $self->[0]->{$key} = $value;
52 my ($self, $key) = @_;
54 return delete $self->[0]->{$key};
60 return %{ $self->[0] };
64 my ($self, $key) = @_;
66 return exists $self->[0]->{$key};
71 $self->_replace and return 'PLPdummy';
72 return each %{$self->[0]};
76 return each %{$_[0]->[0]};