Subject: | by_mediatype doesn't work due to failure to init %list global data structure |
The by_mediatype() method that MIME::Types exports has a strictly
procedural interface. Unfortunately, the internals of by_mediatype()
depend on the %list data structure, and the only way that gets
initialized, currently, is if you call MIME::Types->new().
This behavior is not terribly intuitive from the documentation.
Here's a (fairly nasty, IMO) patch that kludges around the problem:
--- /opt/perl/lib/site_perl/5.10.0/MIME/Types.pm 2009-02-03
06:32:03.000000000 -0500
+++ ./Types.pm 2009-08-28 21:54:43.000000000 -0400
@@ -170,6 +170,8 @@
{ my $type = shift;
my @found;
+ init({}) unless( %list );
+
if(index($type, '/') >= 0)
{ my $simplified = MIME::Type->simplified($type);
my $mime = $list{$simplified};