Subject: | Reading from DATA isn't working with mod_perl |
Using Apache2 (prefork), MIME::Types 1.27 works properly, but version
1.29 isn't consistently loading the entire list of MIME types. When I
have several children loading the module and doing lookups more or less
simultaneously, some of the children only get part of the list.
It should be possible to reproduce this by putting the following code in
a module that gets read as part of every request:
my $class = MIME::Types->new();
my $mime = $class->mimeTypeOf($some_filename_here);
my $type;
if (defined $mime) {
$type = $mime->type();
print STDERR "Found $type (" . scalar($class->types()) . " total)\n";
}
else {
print STDERR "Not Found (" . scalar($class->types()) . " total)\n";
}
When I try it, I'm getting a list of 727 types some of the time, but not
always. Other times, it's only returning between 250 and 500 types.
The attached patch file reverts just the change from
$mime_type_definitions to __DATA__, which fixes the problem.
Subject: | mime-types.bug.patch |
--- Types.pm.orig 2010-06-16 17:35:57.871783255 -0400
+++ Types.pm.new 2010-06-16 17:39:18.315780873 -0400
@@ -17,6 +17,8 @@
my %list;
sub new(@) { (bless {}, shift)->init( {@_} ) }
+my $mime_type_definitions; # see bottom file
+
sub init($)
{ my ($self, $args) = @_;
@@ -24,7 +26,7 @@
{ local $_;
local $/ = "\n";
- while(<DATA>)
+ foreach (split /^/, $mime_type_definitions)
{ chomp;
next if !length $_ or substr($_, 0, 1) eq '#';
@@ -194,14 +196,12 @@
CROAK
}
-1;
-
#-------------------------------------------
# Internet media type registry is at
# http://www.iana.org/assignments/media-types/
# Another list can be found at: http://ftyps.com
-__DATA__
+$mime_type_definitions = <<__MIMETYPES__;
application/activemessage
application/andrew-inset;ez
application/annodex;anx
@@ -1200,3 +1200,7 @@
# IE6 bug
image/pjpeg;;base64
+
+__MIMETYPES__
+
+1;