man > MojoX::MIME::Types(3pm)

```html

MojoX::MIME::Types(3pm) – User Contributed Perl Documentation – MojoX::MIME::Types(3pm)

πŸ“„ NAME

MojoX::MIME::Types – MIME Types for Mojolicious

πŸš€ Quick Reference

Use CaseCommandDescription
Create default MIME types handlerMojoX::MIME::Types->newDrop-in replacement for Mojolicious::Types
Attach to Mojolicious app$app->types(MojoX::MIME::Types->new)Set as the types handler in startup
Use custom MIME::Types objectMojoX::MIME::Types->new(mime_types => $mt)Pass pre-configured MIME::Types instance
Get MIME type by extension$types->type('foo')Returns the first type for extension
Get MIME type by filename$types->file_type($filename)Returns type for a given filename
Set content type on controller$types->content_type($controller, \%options)Sets content type from extension or file
Detect extensions from Accept header$types->detect($accept_header)Returns list of extensions from HTTP Accept
Access underlying MIME::Types$types->mimeTypesGet the full MIME::Types object

🧬 INHERITANCE

πŸ“ SYNOPSIS

use MojoX::MIME::Types;

# set in Mojolicious as default
$app->types(MojoX::MIME::Types->new);
app->types(MojoX::MIME::Types->new);   # ::Lite

# basic interface translated into pure MIME::Types
$types->type(foo => 'text/foo');
say $types->type('foo');

πŸ“– DESCRIPTION

[Added to MIME::Types 2.07] This module is a drop-in replacement for Mojolicious::Types, but with a more correct handling plus a complete list of types… a huge list of types.

Some methods ignore information they receive: those parameters are accepted for compatibility with the Mojolicious::Types interface, but should not contain useful information.

Read the β€œDETAILS” below, about how to connect this module into Mojolicious and the differences you get.

πŸ› οΈ METHODS

πŸ—οΈ Constructors

MojoX::MIME::Types->new(%options)

Create the 'type' handler for Mojolicious. When you do not specify your own MIME::Type object ($mime_type), it will be instantiated for you. You create one yourself when you would like to pass some parameter to the object constructor.

Example:

$app->types(MojoX::MIME::Types->new);

# when you need to pass options to MIME::Types->new
my $mt    = MIME::Types->new(%opts);
my $types = MojoX::MIME::Types->new(mime_types => $mt);
$app->types($types);

πŸ”§ Attributes

$obj->mapping([\%table])

In Mojolicious::Types, this attribute exposes the internal administration of types, offering to change it with using a clean abstract interface. That interface mistake bites now we have more complex internals.

Avoid this method! The returned HASH is expensive to construct, changes passed via %table are ignored: MIME::Types is very complete!

$obj->mimeTypes()

Returns the internal mime types object.

⚑ Actions

$obj->content_type($controller, \%options)

Set a content type on the controller when not yet set. The %options contains β€œext” or β€œfile” specify an file extension or file name which is used to derive the content type. Added and marked EXPERIMENTAL in Mojo 7.94.

$obj->detect($accept, [$prio])

Returns a list of filename extensions. The $accept header in HTTP can contain multiple types, with a priority indication ('q' attributes). The returned list contains a list with extensions, the extensions related to the highest priority type first. The $prio flag is ignored. See MIME::Types::httpAccept().

This detect() function is not the correct approach for the Accept header: the β€œAccept” may contain wildcards ('*') in types for globbing, which does not produce extensions. Better use MIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect().

Example:

my $exts = $types->detect('application/json;q=9');
my $exts = $types->detect('text/html, application/json;q=9');

$obj->file_type($filename)

Return the mime type for a filename. Added and marked EXPERIMENTAL in Mojo 7.94.

$obj->type($ext, [$type|\@types])

Returns the first type name for an extension $ext, unless you specify type names. When a single $type or an ARRAY of @types are specified, the $self object is returned. Nothing is done with the provided info.

πŸ“˜ DETAILS

❓ Why?

The Mojolicious::Types module has only very little knowledge about what is really needed to treat types correctly, and only contains a tiny list of extensions. MIME::Types tries to follow the standards very closely and contains all types found in various lists on internet.

πŸ–₯️ How to use with Mojolicious

Start your Mojo application like this:

package MyApp;
use Mojo::Base 'Mojolicious';

sub startup {
   my $self = shift;
   ...
   $self->types(MojoX::MIME::Types->new);
}

If you have special options for MIME::Types::new(), then create your own MIME::Types object first:

my $mt    = MIME::Types->new(%opts);
my $types = MojoX::MIME::Types->new(mime_types => $mt);
$self->types($types);

In any case, you can reach the smart MIME::Types object later as

my $mt    = $app->types->mimeTypes;
my $mime  = $mt->mimeTypeOf($filename);

πŸ–₯️ How to use with Mojolicious::Lite

The use in Mojolicious::Lite applications is only slightly different from above:

app->types(MojoX::MIME::Types->new);
my $types = app->types;

πŸ”€ Differences with Mojolicious::Types

There are a few major difference with Mojolicious::Types:

πŸ”— SEE ALSO

This module is part of MIME-Types distribution version 2.22, built on October 27, 2021. Website: http://perl.overmeer.net/CPAN/

πŸ“œ LICENSE

Copyrights 1999-2021 by [Mark Overmeer <markov AT cpan.org>]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/

perl v5.32.1 – 2021-11-28 – MojoX::MIME::Types(3pm)

```
MojoX::MIME::Types(3pm)
πŸ“„ NAME πŸš€ Quick Reference 🧬 INHERITANCE πŸ“ SYNOPSIS πŸ“– DESCRIPTION πŸ› οΈ METHODS
πŸ—οΈ Constructors πŸ”§ Attributes ⚑ Actions
πŸ“˜ DETAILS
❓ Why? πŸ–₯️ How to use with Mojolicious πŸ–₯️ How to use with Mojolicious::Lite πŸ”€ Differences with Mojolicious::Types
πŸ”— SEE ALSO πŸ“œ LICENSE

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-28 07:21 @216.73.217.46
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^