.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Mojolicious::Types 3"
.TH Mojolicious::Types 3 "2023-03-08" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Mojolicious::Types \- MIME types
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Mojolicious::Types;
\&
\& my $types = Mojolicious::Types\->new;
\& $types\->type(foo => \*(Aqtext/foo\*(Aq);
\& say $types\->type(\*(Aqfoo\*(Aq);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Mojolicious::Types manages \s-1MIME\s0 types for Mojolicious.
.PP
.Vb 10
\& appcache \-> text/cache\-manifest
\& atom \-> application/atom+xml
\& bin \-> application/octet\-stream
\& css \-> text/css
\& gif \-> image/gif
\& gz \-> application/x\-gzip
\& htm \-> text/html
\& html \-> text/html;charset=UTF\-8
\& ico \-> image/x\-icon
\& jpeg \-> image/jpeg
\& jpg \-> image/jpeg
\& js \-> application/javascript
\& json \-> application/json;charset=UTF\-8
\& mp3 \-> audio/mpeg
\& mp4 \-> video/mp4
\& ogg \-> audio/ogg
\& ogv \-> video/ogg
\& pdf \-> application/pdf
\& png \-> image/png
\& rss \-> application/rss+xml
\& svg \-> image/svg+xml
\& ttf \-> font/ttf
\& txt \-> text/plain;charset=UTF\-8
\& webm \-> video/webm
\& woff \-> font/woff
\& woff2 \-> font/woff2
\& xml \-> application/xml,text/xml
\& zip \-> application/zip
.Ve
.PP
The most common ones are already defined.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
Mojolicious::Types implements the following attributes.
.SS "mapping"
.IX Subsection "mapping"
.Vb 2
\& my $mapping = $types\->mapping;
\& $types = $types\->mapping({png => [\*(Aqimage/png\*(Aq]});
.Ve
.PP
\&\s-1MIME\s0 type mapping.
.SH "METHODS"
.IX Header "METHODS"
Mojolicious::Types inherits all methods from Mojo::Base and implements the following new ones.
.SS "content_type"
.IX Subsection "content_type"
.Vb 1
\& $types\->content_type(Mojolicious::Controller\->new, {ext => \*(Aqjson\*(Aq});
.Ve
.PP
Detect \s-1MIME\s0 type for Mojolicious::Controller object unless a \f(CW\*(C`Content\-Type\*(C'\fR response header has already been set,
defaults to using \f(CW\*(C`application/octet\-stream\*(C'\fR if no better alternative could be found. These options are currently
available:
.IP "ext" 2
.IX Item "ext"
.Vb 1
\& ext => \*(Aqjson\*(Aq
.Ve
.Sp
File extension to get \s-1MIME\s0 type for.
.IP "file" 2
.IX Item "file"
.Vb 1
\& file => \*(Aqfoo/bar.png\*(Aq
.Ve
.Sp
File path to get \s-1MIME\s0 type for.
.SS "detect"
.IX Subsection "detect"
.Vb 1
\& my $exts = $types\->detect(\*(Aqtext/html, application/json;q=9\*(Aq);
.Ve
.PP
Detect file extensions from \f(CW\*(C`Accept\*(C'\fR header value.
.PP
.Vb 2
\& # List detected extensions prioritized
\& say for @{$types\->detect(\*(Aqapplication/json, text/xml;q=0.1\*(Aq, 1)};
.Ve
.SS "file_type"
.IX Subsection "file_type"
.Vb 1
\& my $type = $types\->file_type(\*(Aqfoo/bar.png\*(Aq);
.Ve
.PP
Get \s-1MIME\s0 type for file path.
.SS "type"
.IX Subsection "type"
.Vb 3
\& my $type = $types\->type(\*(Aqpng\*(Aq);
\& $types = $types\->type(png => \*(Aqimage/png\*(Aq);
\& $types = $types\->type(json => [\*(Aqapplication/json\*(Aq, \*(Aqtext/x\-json\*(Aq]);
.Ve
.PP
Get or set \s-1MIME\s0 types for file extension, alternatives are only used for detection.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.