avoid untie replacement for perl v5.18
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 20 Nov 2013 11:13:58 +0000 (12:13 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 20 Nov 2013 11:16:00 +0000 (12:16 +0100)
Replacing a tied hash causes random behaviour and crashes with newer
versions of Perl (probably due to COW changes), so keep the slower tie.

META.yml
lib/PLP/Tie/Delay.pm

index 23a60fd37dc1a8f1ab36eaf2f351442c544b8846..0f653bf9bd8e71cbd8c03ef07fb14fd1c5b992d8 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -50,7 +50,7 @@ provides:
         version: 1.00
     PLP::Tie::Delay:
         file: lib/PLP/Tie/Delay.pm
-        version: 1.00
+        version: 1.01
     PLP::Tie::Headers:
         file: lib/PLP/Tie/Headers.pm
         version: 1.01
index 0a2a0d5f58801d81c666c47dfd9684c906dac9c9..9b9b52f8f55171f2f17232f694f06e0e1eddd60c 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 no strict 'refs';
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 =head1 PLP::Tie::Delay
 
@@ -19,15 +19,16 @@ This module is part of the PLP internals and probably not of any use to others.
 
 sub _replace {
        my ($self) = @_;
-       untie %{ $self->[0] };
 
-       # 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 TIEHASH {
@@ -67,13 +68,12 @@ sub EXISTS {
 
 sub FIRSTKEY {
        my ($self) = @_;
-       $self->_replace;
-       return 'PLPdummy';
+       $self->_replace and return 'PLPdummy';
+       return each %{$self->[0]};
 }
 
 sub NEXTKEY {
-       # Let's hope this never happens. (It's shouldn't.)
-       return undef;
+       return each %{$_[0]->[0]};
 }
 
 sub UNTIE   { }