Bug#677588: perl: Storing shared_clone with overload in shared_clone strips off overload

James McCoy jamessan at debian.org
Fri Jun 15 03:52:03 UTC 2012


Package: perl
Version: 5.14.2-11
Severity: normal
Tags: upstream

The attached script demonstrates the problem through a series of tests.
Basically, after

  my $arr = shared_clone([$objWithOverloads]);
  my $obj = $arr->[0];

$obj no longer behaves the same as $objWithOverloads.  Any of the
overloaded methods defined are no longer invoked automatically in the
relevant contexts.

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.2.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages perl depends on:
ii  libbz2-1.0    1.0.6-3
ii  libc6         2.13-33
ii  libdb5.1      5.1.29-4
ii  libgdbm3      1.8.3-11
ii  perl-base     5.14.2-11
ii  perl-modules  5.14.2-11
ii  zlib1g        1:1.2.7.dfsg-11

Versions of packages perl recommends:
ii  netbase  5.0

Versions of packages perl suggests:
ii  libterm-readline-gnu-perl  1.20-2+b1
ii  make                       3.81-8.2
ii  perl-doc                   5.14.2-11

-- no debconf information
-------------- next part --------------
package FailOverload;
use threads;
use threads::shared;
use overload '""' => 'str',
             'eq' => 'eq';

sub new { return bless({}, $_[0]); }
sub str { is_shared($_[0]) || ref($_[0]) }
sub eq {
    my ($self, $other, $swap) = @_;
    "$self" eq $other;
}

package main;
use strict;
use threads;
use threads::shared;
use Test::Simple tests => 11;

my $fo = FailOverload->new();
ok($fo eq 'FailOverload', 'stringify overload');

my $sFo = shared_clone($fo);
my $id = "$sFo";
ok($sFo eq $id, 'stringify overload shared_clone');

my %h = (fo => $fo, sFo => $sFo);
ok($h{fo} eq 'FailOverload', 'stringify overload from hash');
ok($h{sFo} eq $id, 'stringify overload shared_clone from hash');

my @arr = ($fo, $sFo);
ok($arr[0] eq 'FailOverload', 'stringify overload from array');
ok($arr[1] eq $id, 'stringify overload shared_clone from array');

my $ssFo = shared_clone($sFo);
ok($ssFo eq $id, 'stringify overload double shared');

my $h = shared_clone({sFo => $sFo});
ok($h->{sFo} eq $id, 'stringify overload shared_clone from shared_clone hash');
ok($h->{sFo}->str eq $id, 'call overload str directly');

my $arr = shared_clone([$sFo]);
ok($arr->[0] eq $id, 'stringify overload shared_clone from shared_clone array');
ok($arr->[0]->str eq $id, 'call overload str directly');


More information about the Perl-maintainers mailing list