1Mojolicious::Types(3) User Contributed Perl DocumentationMojolicious::Types(3)
2
3
4

NAME

6       Mojolicious::Types - MIME types
7

SYNOPSIS

9         use Mojolicious::Types;
10
11         my $types = Mojolicious::Types->new;
12         $types->type(foo => 'text/foo');
13         say $types->type('foo');
14

DESCRIPTION

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

ATTRIBUTES

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

METHODS

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       "application/octet-stream" if no better alternative could be found.
67       These options are currently available:
68
69       ext
70           ext => 'json'
71
72         File extension to get MIME type for.
73
74       file
75           file => 'foo/bar.png'
76
77         File path to get MIME type for.
78
79   detect
80         my $exts = $types->detect('text/html, application/json;q=9');
81
82       Detect file extensions from "Accept" header value.
83
84         # List detected extensions prioritized
85         say for @{$types->detect('application/json, text/xml;q=0.1', 1)};
86
87   file_type
88         my $type = $types->file_type('foo/bar.png');
89
90       Get MIME type for file path.
91
92   type
93         my $type = $types->type('png');
94         $types   = $types->type(png => 'image/png');
95         $types   = $types->type(json => ['application/json', 'text/x-json']);
96
97       Get or set MIME types for file extension, alternatives are only used
98       for detection.
99

SEE ALSO

101       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
102
103
104
105perl v5.32.0                      2020-07-28             Mojolicious::Types(3)
Impressum