ssaraogi has asked for the wisdom of the Perl Monks concerning the following question:
#!/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;
|
|---|