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 txt -> text/plain;charset=UTF-8
40 webm -> video/webm
41 woff -> font/woff
42 woff2 -> font/woff2
43 xml -> application/xml,text/xml
44 zip -> application/zip
45
46 The most common ones are already defined.
47
49 Mojolicious::Types implements the following attributes.
50
51 mapping
52 my $mapping = $types->mapping;
53 $types = $types->mapping({png => ['image/png']});
54
55 MIME type mapping.
56
58 Mojolicious::Types inherits all methods from Mojo::Base and implements
59 the following new ones.
60
61 content_type
62 $types->content_type(Mojolicious::Controller->new, {ext => 'json'});
63
64 Detect MIME type for Mojolicious::Controller object unless a
65 "Content-Type" response header has already been set, defaults to using
66 the MIME type for the "txt" extension if no better alternative could be
67 found. Note that this method is EXPERIMENTAL and might change without
68 warning!
69
70 These options are currently available:
71
72 ext
73 ext => 'json'
74
75 File extension to get MIME type for.
76
77 file
78 file => 'foo/bar.png'
79
80 File path to get MIME type for.
81
82 detect
83 my $exts = $types->detect('text/html, application/json;q=9');
84
85 Detect file extensions from "Accept" header value.
86
87 # List detected extensions prioritized
88 say for @{$types->detect('application/json, text/xml;q=0.1', 1)};
89
90 file_type
91 my $type = $types->file_type('foo/bar.png');
92
93 Get MIME type for file path. Note that this method is EXPERIMENTAL and
94 might change without warning!
95
96 type
97 my $type = $types->type('png');
98 $types = $types->type(png => 'image/png');
99 $types = $types->type(json => ['application/json', 'text/x-json']);
100
101 Get or set MIME types for file extension, alternatives are only used
102 for detection.
103
105 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
106
107
108
109perl v5.28.0 2018-10-12 Mojolicious::Types(3)