use Scalar::Util qw(reftype refaddr blessed);
-our $VERSION = '1.24';
+our $VERSION = '1.25';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
elsif ($ref_type eq 'SCALAR') {
$copy = \do{ my $scalar = $$item; };
share($copy);
- # Clone READONLY flag
- if (Internals::SvREADONLY($$item)) {
- Internals::SvREADONLY($$copy, 1);
- }
# Add to clone checking hash
$cloned->{$addr} = $copy;
}
}
# Clone READONLY flag
+ if ($ref_type eq 'SCALAR') {
+ if (Internals::SvREADONLY($$item)) {
+ Internals::SvREADONLY($$copy, 1) if ($] >= 5.008003);
+ }
+ }
if (Internals::SvREADONLY($item)) {
- Internals::SvREADONLY($copy, 1);
+ Internals::SvREADONLY($copy, 1) if ($] >= 5.008003);
}
return $copy;
=head1 VERSION
-This document describes threads::shared version 1.24
+This document describes threads::shared version 1.25
=head1 SYNOPSIS
L<http://www.cpanforum.com/dist/threads-shared>
Annotated POD for L<threads::shared>:
-L<http://annocpan.org/~JDHEDDEN/threads-shared-1.24/shared.pm>
+L<http://annocpan.org/~JDHEDDEN/threads-shared-1.25/shared.pm>
Source repository:
L<http://code.google.com/p/threads-shared/>
BEGIN {
$| = 1;
- print("1..28\n"); ### Number of tests that will be run ###
+ print("1..34\n"); ### Number of tests that will be run ###
};
my $test = 1;
### Start of Testing ###
{
- # Scalar
my $x = shared_clone(14);
ok($test++, $x == 14, 'number');
}
{
+ my $hsh :shared = shared_clone({'foo' => [qw/foo bar baz/]});
+ ok($test++, is_shared($hsh), 'Shared hash ref');
+ ok($test++, is_shared($hsh->{'foo'}), 'Shared hash ref elem');
+ ok($test++, $$hsh{'foo'}[1] eq 'bar', 'Cloned structure');
+}
+
+{
+ my $obj = \do { my $bork = 99; };
+ bless($obj, 'Bork');
+ Internals::SvREADONLY($$obj, 1) if ($] >= 5.008003);
+
+ my $bork = shared_clone($obj);
+ ok($test++, $$bork == 99, 'cloned scalar ref object');
+ ok($test++, Internals::SvREADONLY($$bork), 'read-only');
+ ok($test++, ref($bork) eq 'Bork', 'Object class');
+
+ threads->create(sub {
+ ok($test++, $$bork == 99, 'cloned scalar ref object in thread');
+ ok($test++, Internals::SvREADONLY($$bork), 'read-only');
+ ok($test++, ref($bork) eq 'Bork', 'Object class');
+ })->join();
+
+ $test += 3;
+}
+
+{
my $scalar = 'zip';
my $obj = {
ok($test++, ref($copy) eq 'Foo', 'Cloned object class');
}
-{
- my $hsh :shared = shared_clone({'foo' => [qw/foo bar baz/]});
- ok($test++, is_shared($hsh), 'Shared hash ref');
- ok($test++, is_shared($hsh->{'foo'}), 'Shared hash ref elem');
- ok($test++, $$hsh{'foo'}[1] eq 'bar', 'Cloned structure');
-}
-
exit(0);
# EOF