{
    "mode": "perldoc",
    "parameter": "MojoX::MIME::Types",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MojoX%3A%3AMIME%3A%3ATypes/json",
    "generated": "2026-07-31T07:22:22Z",
    "synopsis": "use MojoX::MIME::Types;\n# set in Mojolicious as default\n$app->types(MojoX::MIME::Types->new);\napp->types(MojoX::MIME::Types->new);   # ::Lite\n# basic interface translated into pure MIME::Types\n$types->type(foo => 'text/foo');\nsay $types->type('foo');",
    "sections": {
        "NAME": {
            "content": "MojoX::MIME::Types - MIME Types for Mojolicious\n",
            "subsections": []
        },
        "INHERITANCE": {
            "content": "MojoX::MIME::Types\nis a Mojo::Base\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use MojoX::MIME::Types;\n\n# set in Mojolicious as default\n$app->types(MojoX::MIME::Types->new);\napp->types(MojoX::MIME::Types->new);   # ::Lite\n\n# basic interface translated into pure MIME::Types\n$types->type(foo => 'text/foo');\nsay $types->type('foo');\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "[Added to MIME::Types 2.07] This module is a drop-in replacement for Mojolicious::Types, but\nwith a more correct handling plus a complete list of types... a huge list of types.\n\nSome methods ignore information they receive: those parameters are accepted for compatibility\nwith the Mojolicious::Types interface, but should not contain useful information.\n\nRead the \"DETAILS\" below, about how to connect this module into Mojolicious and the differences\nyou get.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "MojoX::MIME::Types->new(%options)\nCreate the 'type' handler for Mojolicious. When you do not specify your own MIME::Type\nobject ($mimetype), it will be instantanted for you. You create one yourself when you would\nlike to pass some parameter to the object constructor.\n\n-Option    --Default\nmimetypes  <created internally>\ntypes       undef\n\nmimetypes => MIME::Types-object\nPass your own prepared MIME::Types object, when you need some instantiation parameters\ndifferent from the defaults.\n\ntypes => HASH\nIgnored.\n\nexample:\n\n$app->types(MojoX::MIME::Types->new);\n\n# when you need to pass options to MIME::Types->new\nmy $mt    = MIME::Types->new(%opts);\nmy $types = MojoX::MIME::Types->new(mimetypes => $mt);\n$app->types($types);\n"
                },
                {
                    "name": "Attributes",
                    "content": "$obj->mapping( [\\%table] )\nIn Mojolicious::Types, this attribute exposes the internal administration of types, offering\nto change it with using a clean abstract interface. That interface mistake bites now we have\nmore complex internals.\n\nAvoid this method! The returned HASH is expensive to construct, changes passed via %table\nare ignored: MIME::Types is very complete!\n\n$obj->mimeTypes()\nReturns the internal mime types object.\n"
                },
                {
                    "name": "Actions",
                    "content": "$obj->contenttype($controller, \\%options)\nSet a content type on the controller when not yet set. The %options contains \"ext\" or \"file\"\nspecify an file extension or file name which is used to derive the content type. Added and\nmarked EXPERIMENTAL in Mojo 7.94.\n\n$obj->detect( $accept, [$prio] )\nReturns a list of filename extensions. The $accept header in HTTP can contain multiple\ntypes, with a priority indication ('q' attributes). The returned list contains a list with\nextensions, the extensions related to the highest priority type first. The $prio-flag is\nignored. See MIME::Types::httpAccept().\n\nThis detect() function is not the correct approach for the Accept header: the \"Accept\" may\ncontain wildcards ('*') in types for globbing, which does not produce extensions. Better use\nMIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect().\n\nexample:\n\nmy $exts = $types->detect('application/json;q=9');\nmy $exts = $types->detect('text/html, application/json;q=9');\n\n$obj->filetype($filename)\nReturn the mime type for a filename. Added and marked EXPERIMENTAL in Mojo 7.94.\n\n$obj->type( $ext, [$type|\\@types] )\nReturns the first type name for an extension $ext, unless you specify type names.\n\nWhen a single $type or an ARRAY of @types are specified, the $self object is returned.\nNothing is done with the provided info.\n"
                }
            ]
        },
        "DETAILS": {
            "content": "Why?\nThe Mojolicious::Types module has only very little knowledge about what is really needed to\ntreat types correctly, and only contains a tiny list of extensions. MIME::Types tries to follow\nthe standards very closely and contains all types found in various lists on internet.\n",
            "subsections": [
                {
                    "name": "How to use with Mojolicious",
                    "content": "Start your Mojo application like this:\n\npackage MyApp;\nuse Mojo::Base 'Mojolicious';\n\nsub startup {\nmy $self = shift;\n...\n$self->types(MojoX::MIME::Types->new);\n}\n\nIf you have special options for MIME::Types::new(), then create your own MIME::Types object\nfirst:\n\nmy $mt    = MIME::Types->new(%opts);\nmy $types = MojoX::MIME::Types->new(mimetypes => $mt);\n$self->types($types);\n\nIn any case, you can reach the smart MIME::Types object later as\n\nmy $mt    = $app->types->mimeTypes;\nmy $mime  = $mt->mimeTypeOf($filename);\n"
                },
                {
                    "name": "How to use with Mojolicious::Lite",
                    "content": "The use in Mojolicious::Lite applications is only slightly different from above:\n\napp->types(MojoX::MIME::Types->new);\nmy $types = app->types;\n"
                },
                {
                    "name": "Differences with Mojolicious::Types",
                    "content": "There are a few major difference with Mojolicious::Types:\n\n*   the tables maintained by MIME::Types are complete. So: there shouldn't be a need to add your\nown types, not via \"types()\", not via \"type()\". All attempts to add types are ignored;\nbetter remove them from your code.\n\n*   This plugin understands the experimental flag 'x-' in types and handles casing issues.\n\n*   Updates to the internal hash via types() are simply ignored, because it is expensive to\nimplement (and won't add something new).\n\n*   The detect() is implemented in a compatible way, but does not understand wildcards ('*').\nYou should use MIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect() to replace\nthis broken function.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "This module is part of MIME-Types distribution version 2.22, built on October 27, 2021. Website:\nhttp://perl.overmeer.net/CPAN/\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyrights 1999-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself. See http://dev.perl.org/licenses/\n",
            "subsections": []
        }
    },
    "summary": "MojoX::MIME::Types - MIME Types for Mojolicious",
    "flags": [],
    "examples": [],
    "see_also": []
}