use MIME::Types; my $mt = MIME::Types->new(...); # MIME::Types object my $type = $mt->type('text/plain'); # MIME::Type object my $type = $mt->mimeTypeOf('gif'); my $type = $mt->mimeTypeOf('picture.jpg'); my @types = $mt->httpAccept('text/html, application/json;q=0.1')
"MIME Type" is the old name for "Media Type". This module dates from 1999, and name changes are painful, so we stuck with the original name.
Media types are used in many applications (for instance as part of e-mail and HTTP traffic) to indicate the type of content which is transmitted. or expected. Read RFC6838 at https://www.rfc-editor.org/rfc/rfc6838 (registrations) and RFC9694 at https://www.rfc-editor.org/rfc/rfc9694 (top-levels) for the specification.
Sometimes detailed knowledge about a mime-type is need, however this module only knows about the file-name extensions which relate to some filetype. It can also be used to produce the right format: types which are not registered at IANA need to use 'x-' prefixes.
This object administers a huge list of known mime-types, combined from various sources. For instance, it contains all IANA types and the knowledge of Apache. Probably the most complete table on the net!
If your program uses fork (usually for a daemon), then you want to have the type table initialized before you start forking. So, first call
my $mt = MIME::Types->new;
Later, each time you create this object (you may, of course, also reuse the object you create here) you will get access to the same global table of types.