1MojoX::MIME::Types(3) User Contributed Perl DocumentationMojoX::MIME::Types(3)
2
3
4

NAME

6       MojoX::MIME::Types - MIME Types for Mojolicious
7

INHERITANCE

9        MojoX::MIME::Types
10          is a Mojo::Base
11

SYNOPSIS

13         use MojoX::MIME::Types;
14
15         # set in Mojolicious as default
16         $app->types(MojoX::MIME::Types->new);
17         app->types(MojoX::MIME::Types->new);   # ::Lite
18
19         # basic interface translated into pure MIME::Types
20         $types->type(foo => 'text/foo');
21         say $types->type('foo');
22

DESCRIPTION

24       [Added to MIME::Types 2.07] This module is a drop-in replacement for
25       Mojolicious::Types, but with a more correct handling plus a complete
26       list of types... a huge list of types.
27
28       Some methods ignore information they receive: those parameters are
29       accepted for compatibility with the Mojolicious::Types interface, but
30       should not contain useful information.
31
32       Read the "DETAILS" below, about how to connect this module into
33       Mojolicious and the differences you get.
34

METHODS

36   Constructors
37       MojoX::MIME::Types->new(%options)
38           Create the 'type' handler for Mojolicious.  When you do not specify
39           your own MIME::Type object ($mime_type), it will be instantanted
40           for you.  You create one yourself when you would like to pass some
41           parameter to the object constructor.
42
43            -Option    --Default
44             mime_types  <created internally>
45             types       undef
46
47           mime_types => MIME::Types-object
48             Pass your own prepared MIME::Types object, when you need some
49             instantiation parameters different from the defaults.
50
51           types => HASH
52             Ignored.
53
54           example:
55
56             $app->types(MojoX::MIME::Types->new);
57
58             # when you need to pass options to MIME::Types->new
59             my $mt    = MIME::Types->new(%opts);
60             my $types = MojoX::MIME::Types->new(mime_types => $mt);
61             $app->types($types);
62
63   Attributes
64       $obj->mimeTypes()
65           Returns the internal mime types object.
66
67       $obj->types( [\%table] )
68           In Mojolicious::Types, this attribute exposes the internal
69           administration of types, offering to change it with using a clean
70           abstract interface.  That interface mistake bites now we have more
71           complex internals.
72
73           Avoid this method!  The returned HASH is expensive to construct,
74           changes passed via %table are ignored: MIME::Types is very
75           complete!
76
77   Actions
78       $obj->detect( $accept, [$prio] )
79           Returns a list of filename extensions.  The $accept header in HTTP
80           can contain multiple types, with a priority indication ('q'
81           attributes).  The returned list contains a list with extensions,
82           the extensions related to the highest priority type first.  The
83           $prio-flag is ignored.  See MIME::Types::httpAccept().
84
85           This detect() function is not the correct approach for the Accept
86           header: the "Accept" may contain wildcards ('*') in types for
87           globbing, which does not produce extensions.  Better use
88           MIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect().
89
90           example:
91
92             my $exts = $types->detect('application/json;q=9');
93             my $exts = $types->detect('text/html, application/json;q=9');
94
95       $obj->type( $ext, [$type|\@types] )
96           Returns the first type name for an extension $ext, unless you
97           specify type names.
98
99           When a single $type or an ARRAY of @types are specified, the $self
100           object is returned.  Nothing is done with the provided info.
101

DETAILS

103   Why?
104       The Mojolicious::Types module has only very little knowledge about what
105       is really needed to treat types correctly, and only contains a tiny
106       list of extensions.  MIME::Types tries to follow the standards very
107       closely and contains all types found in various lists on internet.
108
109   How to use with Mojolicious
110       Start your Mojo application like this:
111
112         package MyApp;
113         use Mojo::Base 'Mojolicious';
114
115         sub startup {
116            my $self = shift;
117            ...
118            $self->types(MojoX::MIME::Types->new);
119         }
120
121       If you have special options for MIME::Types::new(), then create your
122       own MIME::Types object first:
123
124         my $mt    = MIME::Types->new(%opts);
125         my $types = MojoX::MIME::Types->new(mime_types => $mt);
126         $self->types($types);
127
128       In any case, you can reach the smart MIME::Types object later as
129
130         my $mt    = $app->types->mimeTypes;
131         my $mime  = $mt->mimeTypeOf($filename);
132
133   How to use with Mojolicious::Lite
134       The use in Mojolicious::Lite applications is only slightly different
135       from above:
136
137         app->types(MojoX::MIME::Types->new);
138         my $types = app->types;
139
140   Differences with Mojolicious::Types
141       There are a few major difference with Mojolicious::Types:
142
143       ·   the tables maintained by MIME::Types are complete.  So: there
144           shouldn't be a need to add your own types, not via types(), not via
145           type().  All attempts to add types are ignored; better remove them
146           from your code.
147
148       ·   This plugin understands the experimental flag 'x-' in types and
149           handles casing issues.
150
151       ·   Updates to the internal hash via types() are simply ignored,
152           because it is expensive to implement (and won't add something new).
153
154       ·   The detect() is implemented in a compatible way, but does not
155           understand wildcards ('*').  You should use
156           MIME::Types::httpAcceptBest() or MIME::Types::httpAcceptSelect() to
157           replace this broken function.
158

SEE ALSO

160       This module is part of MIME-Types distribution version 2.17, built on
161       January 26, 2018. Website: http://perl.overmeer.net/CPAN/
162

LICENSE

164       Copyrights 1999-2018 by [Mark Overmeer <markov@cpan.org>]. For other
165       contributors see ChangeLog.
166
167       This program is free software; you can redistribute it and/or modify it
168       under the same terms as Perl itself.  See http://dev.perl.org/licenses/
169
170
171
172perl v5.32.0                      2020-07-28             MojoX::MIME::Types(3)
Impressum