1Mojolicious::Types(3) User Contributed Perl DocumentationMojolicious::Types(3)
2
3
4
6 Mojolicious::Types - MIME types
7
9 use Mojolicious::Types;
10
11 my $types = Mojolicious::Types->new;
12 $types->type(foo => 'text/foo');
13 say $types->type('foo');
14
16 Mojolicious::Types manages MIME types for Mojolicious.
17
18 appcache -> text/cache-manifest
19 atom -> application/atom+xml
20 bin -> application/octet-stream
21 css -> text/css
22 gif -> image/gif
23 gz -> application/x-gzip
24 htm -> text/html
25 html -> text/html;charset=UTF-8
26 ico -> image/x-icon
27 jpeg -> image/jpeg
28 jpg -> image/jpeg
29 js -> application/javascript
30 json -> application/json;charset=UTF-8
31 mp3 -> audio/mpeg
32 mp4 -> video/mp4
33 ogg -> audio/ogg
34 ogv -> video/ogg
35 pdf -> application/pdf
36 png -> image/png
37 rss -> application/rss+xml
38 svg -> image/svg+xml
39 ttf -> font/ttf
40 txt -> text/plain;charset=UTF-8
41 webm -> video/webm
42 woff -> font/woff
43 woff2 -> font/woff2
44 xml -> application/xml,text/xml
45 zip -> application/zip
46
47 The most common ones are already defined.
48
50 Mojolicious::Types implements the following attributes.
51
52 mapping
53 my $mapping = $types->mapping;
54 $types = $types->mapping({png => ['image/png']});
55
56 MIME type mapping.
57
59 Mojolicious::Types inherits all methods from Mojo::Base and implements
60 the following new ones.
61
62 content_type
63 $types->content_type(Mojolicious::Controller->new, {ext => 'json'});
64
65 Detect MIME type for Mojolicious::Controller object unless a
66 "Content-Type" response header has already been set, defaults to using
67 "application/octet-stream" if no better alternative could be found.
68 These options are currently available:
69
70 ext
71 ext => 'json'
72
73 File extension to get MIME type for.
74
75 file
76 file => 'foo/bar.png'
77
78 File path to get MIME type for.
79
80 detect
81 my $exts = $types->detect('text/html, application/json;q=9');
82
83 Detect file extensions from "Accept" header value.
84
85 # List detected extensions prioritized
86 say for @{$types->detect('application/json, text/xml;q=0.1', 1)};
87
88 file_type
89 my $type = $types->file_type('foo/bar.png');
90
91 Get MIME type for file path.
92
93 type
94 my $type = $types->type('png');
95 $types = $types->type(png => 'image/png');
96 $types = $types->type(json => ['application/json', 'text/x-json']);
97
98 Get or set MIME types for file extension, alternatives are only used
99 for detection.
100
102 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
103
104
105
106perl v5.36.0 2022-07-22 Mojolicious::Types(3)