Subject: | Bad filehandle error with Devel::Profile |
A simple script to set and get a value in memcached, which works normally, fails with an error when used with -d:Profile to profile the script with the Devel::Profile CPAN module. The error is produced from one of the IO or Socket modules (Carp is used so the error says it is from Devel::Profile):
$ perl memcached.pl
100
$ perl -d:Profile memcached.pl
Bad filehandle: Sock_127.0.0.1:11211 at /usr/lib/perl5/site_perl/5.8.0/Devel/Profile.pm line 133.
memcached.pl test script follows:
#!/usr/bin/perl
use strict;
use warnings;
use Cache::Memcached;
my $memd = new Cache::Memcached {
'servers' => [ '127.0.0.1:11211' ],
'debug' => 0,
'compress_threshold' => 10_000,
};
profile_me();
sub profile_me {
$memd->set('TEST', 100);
print $memd->get('TEST'), "\n";
}
__END__
The attached diff changes one line in the Cache::Memcached module that generates the socket handle name to include the package name, which seems to placate Devel::Profile, and the test script then runs normally, plus you get your "prof.out" profile output file as expected.
- Martin Flack
--- Memcached.pm.orig 2005-12-06 21:30:24.000000000 +0000
+++ Memcached.pm.mod 2005-12-06 21:30:29.000000000 +0000
@@ -215,7 +215,7 @@
my ($ip, $port) = $host =~ /(.*):(\d+)/;
return undef if
$host_dead{$host} && $host_dead{$host} > $now;
- my $sock = "Sock_$host";
+ my $sock = __PACKAGE__."::Sock_$host";
my $connected = 0;
my $sin;