Can someone explain why this is a problem?
Because that's what the File-MMagic README says?
5. Notice
If you want to use the module under mod_perl environment, you'll need
to divide the module into module part and magic entry file part, and use
the magic file explicitly.
Built-in magic entry does not work correctly under mod_perl.
If the authors says it doesn't work correctly I tend to believe :)
On the other hand, if its working for you, go for it.
Examining the source it seems as if every time
File::MMagic->new is invoked, File::MMagic reads from its DATA section,
and it seems to me like that should be done at most once, so here's an untested replacement for sub new
my $do_data_magic_only_once = undef;
sub new {
my $self = {};
my $proto = shift;
my $class = ref($proto) || $proto;
$self->{MF} = [];
$self->{magic} = [];
if (! @_) {
if( $do_data_magic_only_once ){
$self->{magic} = $do_data_magic_only_once;
} else {
my $fh = *File::MMagic::DATA{IO};
binmode($fh);
bless $fh, 'FileHandle' if ref $fh ne 'FileHandle';
my $dataLoc;
# code block to localise the no strict;, contribute by Sim
+on Matthews
{
no strict 'refs';
my $instance = \${ "$class\::_instance" };
$$instance = $fh->tell() unless $$instance;
$dataLoc = $$instance;
}
$fh->seek($dataLoc, 0);
&readMagicHandle($self, $fh);
$do_data_magic_only_once = $self->{magic};
}
} else {
my $filename = shift;
my $fh = new FileHandle;
if ($fh->open("< $filename")) {
binmode($fh);
&readMagicHandle($self, $fh);
} else {
warn __PACKAGE__ . " couldn't load specified file $filename";
}
}
# from the BSD names.h, some tokens for hard-coded checks of
# different texts. This isn't rocket science. It's prone to
# failure so these checks are only a last resort.
# removSpecials() can be used to remove those afterwards.
$self->{SPECIALS} = {
"message/rfc822" => [ "^Received:",
"^>From ",
"^From ",
"^To: ",
"^Return-Path: ",
"^Cc: ",
"^X-Mailer: "],
"message/news" => [ "^Newsgroups: ",
"^Path: ",
"^X-Newsreader: "],
"text/html" => [ "<html[^>]*>",
"<HTML[^>]*>",
"<head[^>]*>",
"<HEAD[^>]*>",
"<body[^>]*>",
"<BODY[^>]*>",
"<title[^>]*>",
"<TITLE[^>]*>",
"<h1[^>]*>",
"<H1[^>]*>",
],
"text/x-roff" => [
'^\\.\\\\"',
"^\\.SH ",
"^\\.PP ",
"^\\.TH ",
"^\\.BR ",
"^\\.SS ",
"^\\.TP ",
"^\\.IR ",
],
};
$self->{FILEEXTS} = {
'\.gz$' => 'application/x-gzip',
'\.bz2$' => 'application/x-bzip2',
'\.Z$' => 'application/x-compress',
'\.txt$' => 'text/plain',
'\.html$' => 'text/html',
'\.htm$' => 'text/html',
};
bless($self);
return $self;
}
MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" | I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). | ** The third rule of perl club is a statement of fact: pod is sexy. |
|