Create the type handler for Mojolicious. When you do not specify your
own MIME::Type object ($mime_type), it will be instantanted for you.
You create one yourself when you would like to pass some parameter to
the object constructor.
$obj-><B>mimeTypesB>() Returns the internal mime types object. $obj-><B>typesB>( [\%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.
$obj-><B>detectB>( $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().
my $exts = $types->detect(application/json;q=9); my $exts = $types->detect(text/html, application/json;q=9);
$obj-><B>typeB>( $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.
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.
Start your Mojo application like this:
In any case, you can reach the smart MIME::Types object later as
my $mt = $app->types->mimeTypes; my $mime = $mt->mimeTypeOf($filename);
The use in Mojolicious::Lite applications is only slightly different from above:
app->types(MojoX::MIME::Types->new); my $types = app->types;
There are a few major difference with Mojolicious::Types:
o the tables maintained by MIME::Types are complete. So: there shouldnt be a need to add your own types, not via types(), not via type(). All attempts to add types are ignored; better remove them from your code. o This plugin understands the experimental flag x- in types and handles casing issues. o Updates to the internal hash via types() are simply ignored, because it is expensive to implement (and wont add something new). o The detect() is implemented in a compatible way, but does not understand wildcards (*). You should use MIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect() to replace this broken function.
This module is part of MIME-Types distribution version 2.13, built on March 07, 2016. Website: http://perl.overmeer.net/mimetypes/
Copyrights 1999,2001-2016 by [Mark Overmeer]. 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://www.perl.com/perl/misc/Artistic.html
|perl v5.20.3||MOJOX::MIME::TYPES (3)||2016-03-07|