.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 3pm" .TH Mojolicious::Types 3pm 2024-05-15 "perl v5.38.2" "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 MIME 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 MIME 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 MIME 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 MIME type for. .IP file 2 .IX Item "file" .Vb 1 \& file => \*(Aqfoo/bar.png\*(Aq .Ve .Sp File path to get MIME 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 MIME 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 MIME types for file extension, alternatives are only used for detection. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .