Thanks. unfortunately that solution fails to lock ordinary non-reference data types.
I also found d(un)?lock loops forever on circular reference.
the patch below fix all that. New version on its way to CPAN.
Dan
On Wed Mar 20 10:28:49 2013, GFUJI wrote:
Show quoted text> Try `perl -e 'use Data::Lock qw(dlock); dlock "0"; $0 = "hoge"'`,
> which will fail.
>
> "no strict 'refs'" seems the fault. "use strict 'refs'" again in the
> (un)lock routines.
diff -u -r0.4 lib/Data/Lock.pm
--- lib/Data/Lock.pm 2013/03/20 22:17:40 0.4
+++ lib/Data/Lock.pm 2013/03/20 22:29:19
@@ -19,6 +19,7 @@
*{$subname} = sub {
no warnings "uninitialized";
return if Internals::SvREADONLY( $_[0]) == $locked;
+ Internals::SvREADONLY( $_[0], $locked );
my $type = Scalar::Util::reftype( $_[0] );
for (
$type eq 'ARRAY' ? @{ $_[0] }
@@ -27,14 +28,13 @@
: ()
)
{
- dlock($_) if ref $_;
+ &$subname($_) if ref $_;
Internals::SvREADONLY( $_, $locked );
}
$type eq 'ARRAY' ? Internals::SvREADONLY( @{ $_[0] }, $locked )
: $type eq 'HASH' ? Internals::SvREADONLY( %{ $_[0] }, $locked )
: $type ne 'CODE' ? Internals::SvREADONLY( ${ $_[0] }, $locked )
: undef;
- Internals::SvREADONLY( $_[0], $locked );
};
}