.\" Automatically generated by Pod::Man 4.09 (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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Parse::MIME 3pm" .TH Parse::MIME 3pm "2018-05-06" "perl v5.26.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" Parse::MIME \- Parse mime\-types, match against media ranges .SH "VERSION" .IX Header "VERSION" version 1.003 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Parse::MIME qw( best_match ); \& print best_match( [ qw( application/xbel+xml text/xml ) ], \*(Aqtext/*;q=0.5,*/*; q=0.1\*(Aq ); \& # text/xml .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides basic functions for handling mime-types. It can handle matching mime-types against a list of media-ranges. See section 14.1 of the \&\s-1HTTP\s0 specification [\s-1RFC 2616\s0] for a complete explanation: .SH "INTERFACE" .IX Header "INTERFACE" None of the following functions are exported by default. You can use the \&\f(CW\*(C`:all\*(C'\fR tag to import all of them into your package: .PP .Vb 1 \& use Parse::MIME \*(Aq:all\*(Aq; .Ve .SS "parse_mime_type" .IX Subsection "parse_mime_type" Parses a mime-type into its component parts and returns type, subtype and params, where params is a reference to a hash of all the parameters for the media range: .PP .Vb 2 \& parse_mime_type \*(Aqapplication/xhtml;q=0.5\*(Aq \& # ( \*(Aqapplication\*(Aq, \*(Aqxhtml\*(Aq, { q => 0.5 } ) .Ve .SS "parse_media_range" .IX Subsection "parse_media_range" Media-ranges are mime-types with wild-cards and a \f(CW\*(C`q\*(C'\fR quality parameter. This function works just like \*(L"parse_mime_type\*(R", but also guarantees that there is a value for \f(CW\*(C`q\*(C'\fR in the params hash, supplying the default value if necessary. .PP .Vb 2 \& parse_media_range \*(Aqapplication/xhtml\*(Aq \& # ( \*(Aqapplication\*(Aq, \*(Aqxhtml\*(Aq, { q => 1 } ) .Ve .SS "parse_media_range_list" .IX Subsection "parse_media_range_list" Media-range lists are comma-separated lists of media ranges. This function works just like \*(L"parse_media_range\*(R", but accepts a list of media ranges and returns for all of media-ranges. .PP .Vb 2 \& my @l = parse_media_range_list \*(Aqapplication/xhtml, text/html;q=0.7\*(Aq \& # ( \*(Aqapplication\*(Aq, \*(Aqxhtml\*(Aq, { q => 1 }, \*(Aqtext\*(Aq, \*(Aqhtml\*(Aq, { q => 0.7 } ) .Ve .SS "fitness_and_quality_parsed" .IX Subsection "fitness_and_quality_parsed" Find the best match for a given mime-type (passed as the first parameter) against a list of media ranges that have already been parsed by \&\*(L"parse_media_range\*(R" (passed as a flat list). Returns the fitness value and the value of the \f(CW\*(C`q\*(C'\fR quality parameter of the best match, or \f(CW\*(C`( \-1, 0 )\*(C'\fR if no match was found. .PP .Vb 3 \& # for @l see above \& fitness_and_quality_parsed( \*(Aqtext/html\*(Aq, @l ) \& # ( 110, 0.7 ) .Ve .SS "quality" .IX Subsection "quality" Determines the quality (\f(CW\*(C`q\*(C'\fR) of a mime-type (passed as the first parameter) when compared against a media-range list string. F.ex.: .PP .Vb 2 \& quality( \*(Aqtext/html\*(Aq, \*(Aqtext/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5\*(Aq ) \& # 0.7 .Ve .SS "quality_parsed" .IX Subsection "quality_parsed" Just like \*(L"quality\*(R", except the second parameter must be pre-parsed by \&\*(L"parse_media_range_list\*(R". .SS "best_match" .IX Subsection "best_match" Choose the mime-type with the highest quality (\f(CW\*(C`q\*(C'\fR) from a list of candidates. Takes an array of supported mime-types as the first parameter and finds the best match for all the media-ranges listed in header, which is passed as the second parameter. The value of header must be a string that conforms to the format of the \s-1HTTP\s0 \f(CW\*(C`Accept\*(C'\fR header. F.ex.: .PP .Vb 2 \& best_match( [ qw( application/xbel+xml text/xml ) ], \*(Aqtext/*;q=0.5,*/*; q=0.1\*(Aq ) \& # \*(Aqtext/xml\*(Aq .Ve .SH "AUTHOR" .IX Header "AUTHOR" Aristotle Pagaltzis .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2015 by Aristotle Pagaltzis. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.