ssaraogi has asked for the wisdom of the Perl Monks concerning the following question:

I am using Test::MockModule in one of my unit tests which fails in the debug mode (perl -d <test>) but passes in the normal mode (perl <test>)

After some debugging, i found it to be a weak reference not getting destroyed in the debug mode.

I tried searching for similar issues but could not find anything related so far. I am not able to further figure out what the issue is here and needed help.
What could be the issue here? Is this a known issue?

Following code reproduces this issue:

>> ./repro.pl
Use of uninitialized value $weak_objref in concatenation (.) or string at repro.pl line 48.

>> perl -d ./repro.pl
Package=HASH(0x68e068)

repro.pl
--------
#!/home/utils/perl-5.10/5.10.1-nothreads-64/bin/perl use strict; use warnings FATAL => 'all'; use Scalar::Util qw(weaken); my $package_name = 'Package'; my $method_name = 'method'; my $weak_objref; { # This function creates a weak object reference and returns a code + reference sub create_weak_objref { # create any object my $self = bless {}, $package_name; # make a weak reference to the above created object $weak_objref = $self; weaken( $weak_objref ); # return a code reference which mucks around with the above cr +eated object return sub { # Need following to be able to use the string $resolved_me +thod_name later as symbol reference no strict 'refs'; # Both the following steps needs to be done to be able to +reproduce bug in the debug mode # Skipping any of them or moving any out to the parent met +hod does not reproduce the bug # set any arbitrary data inside the object $self->{_arbit_data} = 1; # update packages symbol table to create method 'method_na +me' my $resolved_method_name = "${package_name}::{${method_nam +e}}"; *{$resolved_method_name} = sub {}; }; }; my $coderef = create_weak_objref(); # call the returned code reference $coderef->(); } # Weak reference should be undefined here - but it does get printed in + the debug mode :( print "$weak_objref\n"; 1;