Replacing a tied hash causes random behaviour and crashes with newer
versions of Perl (probably due to COW changes), so keep the slower tie.
version: 1.00
PLP::Tie::Delay:
file: lib/PLP/Tie/Delay.pm
version: 1.00
PLP::Tie::Delay:
file: lib/PLP/Tie/Delay.pm
PLP::Tie::Headers:
file: lib/PLP/Tie/Headers.pm
version: 1.01
PLP::Tie::Headers:
file: lib/PLP/Tie/Headers.pm
version: 1.01
no strict 'refs';
use warnings;
no strict 'refs';
use warnings;
sub _replace {
my ($self) = @_;
sub _replace {
my ($self) = @_;
- # I'd like to use *{ $self->[0] } = $self->[1]->(); here,
- # but that causes all sorts of problems. The hash is accessible from
- # within this sub, but not where its creation was triggered.
- # Immediately after the triggering statement, the hash becomes available
- # to all: even the scope where the previous access attempt failed.
-
- %{ $self->[0] } = %{ $self->[1]->() }
+ if ($] >= 5.018) {
+ my $code = delete $self->[1] or return;
+ $self->[0] = $code->();
+ return 1;
+ }
+
+ untie %{ $self->[0] };
+ %{ $self->[0] } = %{ $self->[1]->() }; # *{ $self->[0] } = $self->[1]->();
+ return;
sub FIRSTKEY {
my ($self) = @_;
sub FIRSTKEY {
my ($self) = @_;
- $self->_replace;
- return 'PLPdummy';
+ $self->_replace and return 'PLPdummy';
+ return each %{$self->[0]};
- # Let's hope this never happens. (It's shouldn't.)
- return undef;
+ return each %{$_[0]->[0]};