MojoX::MIME::Types(3)
Welcome to the User Contributed Perl Documentation page for MojoX::MIME::Types(3) π. Buckle up, bestie β this is the manual page for MojoX::MIME::Types, and it's giving MIME types for Mojolicious with main-character energy. β¨
π NAME π
MojoX::MIME::Types β MIME Types for Mojolicious π
π INHERITANCE π
MojoX::MIME::Types is a Mojo::Base π«Ά
β¨ 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');
That's the whole vibe: set it as the default, then use the basic interface that gets translated into pure MIME::Types. Slay. π
Periodt.
π DESCRIPTION π
Hot gossip:[Added to MIME::Types 2.07]β this module is a drop-in replacement forMojolicious::Types, but with a more correct handling plus a complete list of types... a huge list of types. π Not me being obsessed with a MIME list, but here we are.
Some methods literally ignore information they receive: those parameters are accepted for compatibility with the Mojolicious::Types interface, but they should not contain useful information. So don't put your hopes and dreams in them, okay? π
Read the DETAILS below for how to connect this module into Mojolicious and the differences you get. It's giving plot twist, but useful. π
π οΈ METHODS π οΈ
Constructors π§
$class->new(%options)
Create the 'type' handler for Mojolicious. When you do not specify your own MIME::Type object ("mime_types"), it will be instantiated for you. You create one yourself when you would like to pass some parameter to the object constructor.
-Option --Default
mime_types <created internally>
types undef
mime_types=>MIME::Types-object β default<created internally>. Pass your own preparedMIME::Typesobject when you need some instantiation parameters different from the defaults. πtypes=>HASHβ defaultundef. Ignored. π
Example, because yes: β¨
$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 returnedHASHis expensive to construct, changes passed via%tableare ignored:MIME::Typesis very complete! π₯
$obj->mimeTypes()
Returns the internal mime types object. That's it. No cap. π
Actions β‘
$obj->content_type($controller, \%options)
Set a content type on the controller when not yet set. The %options contains "ext" or "file" β those specify a 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().
Real talk, bestie: Thisdetect()function is not the correct approach for theAcceptheader: the"Accept"may contain wildcards ('*') in types for globbing, which does not produce extensions. Better useMIME::Types::httpAcceptBest()orMIME::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 current object is returned. Nothing is done with the provided info. Literally nothing. π
π 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. It's giving glow-up. π iykyk.
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 differences with Mojolicious::Types:
- the tables maintained by
MIME::Typesare complete. So: there shouldn't be a need to add your own types, not viatypes(), not viatype(). All attempts to add types are ignored; better remove them from your code. - This plugin understands the experimental flag
'x-'in types and handles casing issues. β¨ - Updates to the internal hash via
types()are simply ignored, because it is expensive to implement (and won't add something new). π - The
detect()is implemented in a compatible way, but does not understand wildcards ('*'). You should useMIME::Types::httpAcceptBest()orMIME::Types::httpAcceptSelect()to replace this broken function. π
π SEE ALSO π
This module is part of MIME-Types version 2.30, built on December 08, 2025. Website: http://perl.overmeer.net/CPAN/ π
π LICENSE π
For contributors see file ChangeLog.
This software is copyright (c) 1999-2025 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Okay, that's the page! π«Ά Cute sign-off: source/version is MIME-Types version 2.30, built on December 08, 2025; the footer says perl v5.42.2, 2025-12-09, and MojoX::MIME::Types(3). Stay slaying those MIME types, bestie. π
β¨
π¦ where this page comes from
- alpine 3.24: perl-mime-types-doc 2.30-r0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms