Media-Type-Simple reviews

RSS | Module Info

Media-Type-Simple (v0.31.0)

Since there doesn't seem to be a "Media::Type" or even a "Media::Type::Complicated" or "Media::Type::Difficult" the naming of the module is somewhat suspect.

The module itself is very unpretentious, only mapping from file extensions to mime types and back.

So far so good, but it dies if you send it an extension it doesn't recognize, rather than just returning the undefined value:

eval {

my $media_type = type_from_ext ('kangaroo');
if ($@) {

print "Died like this: $@";

$ perl
Died like this: Unknown extension: kangaroo at line 8.

That means one has to wrap every single use in an eval in case some file or another has some unknown extension. Throwing a fatal error when the user sends something of unknown type is not a good practice. That is like inviting people to ask you questions, and then pulling out a gun and shooting someone if they ask you a question you don't know the answer to. Just say "I don't know", and return the undefined value!

On various types of file it gives more or less identical results to File::MimeInfo, with a few exceptions. For example ".bmp" got me "image/x-ms-bmp" with this but "image/bmp" with File::MimeInfo, and .gz got me "application/x-gzip" from this, but "application/gzip" from MIME::Types and File::MimeInfo.

For a full comparison including source code and results on various files, see

Media-Type-Simple (0.02) ***

At the time of this review, this module doesn't work in forked environments due to its use of an internally cached filehandle. The bug for the issue is nine months old now :-/

Otherwise, I would use this module over File::Type, particularly if you need to get a MIME type for a text file (File::Type tends to call them all application/octet-stream, whereas this module gets it right).