in reply to Perl compiler breaks using Test::Resub

It looks like the offending code in Test::Resub is this:

... if ($capture{$ident}) { local $Storable::Deparse = 1; local $Storable::Eval = 1; my $saved_args = $deep_copy{$ident} ? dclone([@_]) : [@_]; push @{$method_args{$ident}}, $saved_args; } ...

... so that would seem to me that maybe your actual objects store callbacks as part of their data somewhere, and at least one of these callbacks can't be deparsed by B::Deparse (maybe because it's a function implemented in XS).

But without seeing more of your code, preferrably a self-contained short program that still exhibits the same problem, it's only guesswork.

A workaround would be to specify capture => 0, but I'm not sure what implications that has for your test. Likely you won't know with what arguments your subroutine was called. Personally, I don't see what benefit Test::Resub has over simply replacing the function yourself:

{ my @args; local *Aclass::doit = sub { push @args, [@_]; return 42; }; $boss_worker->doit; is 0+@args, 3, "We got called three times"; is_deeply \@args, [[...], [...], [...] ]; }

Update: Rereading your post topic, are you using the "Perl compiler" perlcc? It has been discontinued in Perl 5.10 (or at least Perl 5.12), as it never really worked. If it fails to work for you, that's unsurprising, and a fix is unlikely to be in sight.

Replies are listed 'Best First'.
Re^2: Perl compiler breaks using Test::Resub
by ron7 (Beadle) on Feb 04, 2011 at 01:23 UTC
    Thanks all

    I found the problem late last night and looks like Corion had picked the root cause. The constructor of the class giving trouble was creating an object in $self that could not be serialized, hence the problem when Resub tried to capture @_ that would be passed into the real sub.

    As there was no need for the ref to it to be in $self, I removed it and replaced it with a lazy "getter", now all is well.

    Re the perlcc question, my app (27,351 LOC in all modules) uses Tk and I distribute binaries for Win32, Unix, and OSX using ActiveState perlapp to create them (plus the source which I think nobody looks at). Sadly, ActiveState dropped Tk after 5.8, so I HAVE to use 5.8.x. Them's the breaks...

Re^2: Perl compiler breaks using Test::Resub
by rurban (Scribe) on Apr 25, 2011 at 12:21 UTC