Subject: | Can't call method "remove" on an undefined value |
Date: | Thu, 23 Aug 2012 22:01:20 +1200 |
To: | bug-pid-file [...] rt.cpan.org |
From: | Holger Jahn <holger [...] loomsday.co.nz> |
Hi Rob,
We have been scratching our collective heads here for a while, since we
always got greeted with the funny error message below:
(in cleanup) Can't call method "remove" on an undefined value at
/usr/local/perl2exe/perl5/lib/site_perl/5.10.0/PID/File.pm line 322
during global destruction.
This message is thrown when we were calling to call the "guard" method
on a global variable when the script is exiting, like so:
use PID::File;
my $pid_file;
sub make_pid_file {
$pid_file = PID::File->new;
$pid_file->file('pidfile');
$pid_file->create;
$pid_file->guard if $pid_file;
print "pidfile created $$\n";
system("ls -l pidfile");
}
make_pid_file();
system("ls -l pidfile");
exit;
When we kept the scope local, i.e. with "my $pid_file" inside the
function, then the error is not thrown, but the PID file is removed when
the functions returns to its caller.
After a while, I figured that PID::File started working correctly after
changing line number 337 in PID/File.pm, like so:
$self->remove;
# $self->{ guard }->();
It would be great if you could have another look at the DESTROY function
and see if my patch makes any sense.
Many thanks & Kind regards,
Holger