Mark Stosberg wrote:
Hello, Recently I ran into a bug with File::MMagic where it returns inconsistent results under mod_perl. Could it simply be a matter of fixing the use of the DATA handle, as Stats suggest here? http://mail-archives.apache.org/mod_mbox/perl-modperl/200403.mbox/suppressed
Yep. It's definitly the problem. The work around is to pass a magicdefinition file into MMagic when the object is created. Easier said than done.
Maybe the best solution is move the DATA section to a variable. It's not as elegant as reading the data from a DATA section, but it's mod_perl compliant.Hmm... You might try adding this to your startup.pl (or whatever is per-loading perl modules).
# a bit of a hack
use vars qw($magicObject);
BEGIN {
if($ENV{MOD_PERL}) {
# load from <DATA>
$magicObject = File::MMagic->new();
# save it globally
{
no strict;
# save original method
*{"File::MMagic::original_new"} = *{"File::MMagic::new"}{CODE};
# replace original method
*{"File::MMagic::new"} = sub {
return $magicObject;
};
} # end no strict
}
}
It's untested. And it probably leaks memory, too. :(
Rob
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.