in reply to Re: Subtle(?) issue(?) with lvalues and serialization
in thread Subtle(?) issue(?) with lvalues and serialization

... because they should at least warn about LVALUEs not being handled correctly ...

Now hold on for a second:

Warn? Yes a warning would have been nice. Not handled correctly? No.

Documentation of Storage promises that Storage will work for SCALAR, ARRAY, HASH or REF objects:

... persistence to your Perl data structures containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be conveniently stored to disk and retrieved at a later time.

There is no promise that Storage will handle lvalue's and it doesn't, so one may actually reason it is functioning correctly.

The example script below first shows the effect of storing the lvalue in an array and changing it to undef outside of the array. After that it shows that the same behavior cannot be observed after using the Storage. The lvalue is invalidated and becomes undef. Same behavior can be observed when the lvalue is inside a hash, also the correct behavior if you ask me. I do believe a warning would have been nice though:

use strict ; use warnings ; use Storable qw( freeze thaw ) ; use Data::Dumper ; my $abc = "abc" ; my @ar = ( \( substr( $abc, 0 ) ) ) ; print "ar_0 = ${$ar[0]}\n" ; my $def = "def" ; my @ar2 = ( \( substr( $def, 0 ) ) ) ; $def = undef ; print "ar2_0 = ${$ar2[0]}\n" ; $def = 'def' ; print "ar2_0 = ${$ar2[0]}\n" ; my $serialized1 = freeze \$abc ; my $serialized2 = freeze \substr $def, 0 ; $abc = 'ghi' ; $def = 'jkl' ; $abc = ${ thaw( $serialized1 ) } ; $def = ${ thaw( $serialized2 ) } ; print "thaw abc = $abc\n" ; print "thaw def = $def\n" ; my $xyz = "xyz" ; my %xyz = ( _xyz => \substr $xyz, 0 ) ; my $ser_xyz = freeze \%xyz ; $xyz = "uvw" ; my %copyxyz = %{ thaw( $ser_xyz ) } ; print Dumper( \%copyxyz ) ; __END__ ar_0 = abc Use of uninitialized value in concatenation (.) or string at test2.pl +line 13. ar2_0 = ar2_0 = def thaw abc = abc Use of uninitialized value $def in concatenation (.) or string at test +2.pl line 25. thaw def = $VAR1 = { '_xyz' => \undef };