GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PARSE::MIME (3)

.ds Aq ’

NAME

Parse::MIME - Parse mime-types, match against media ranges

CONTENTS

VERSION

version 1.003

SYNOPSIS



 use Parse::MIME qw( best_match );
 print best_match( [ qw( application/xbel+xml text/xml ) ], text/*;q=0.5,*/*; q=0.1 );
 # text/xml



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 HTTP specification [RFC 2616] for a complete explanation: <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1>

INTERFACE

None of the following functions are exported by default. You can use the :all tag to import all of them into your package:



 use Parse::MIME :all;



    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:



 parse_mime_type application/xhtml;q=0.5
 # ( application, xhtml, { q => 0.5 } )



    parse_media_range

Media-ranges are mime-types with wild-cards and a q quality parameter. This function works just like parse_mime_type, but also guarantees that there is a value for q in the params hash, supplying the default value if necessary.



 parse_media_range application/xhtml
 # ( application, xhtml, { q => 1 } )



    parse_media_range_list

Media-range lists are comma-separated lists of media ranges. This function works just like parse_media_range, but accepts a list of media ranges and returns for all of media-ranges.



 my @l = parse_media_range_list application/xhtml, text/html;q=0.7
 # ( application, xhtml, { q => 1 }, text, html, { q => 0.7 } )



    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 parse_media_range (passed as a flat list). Returns the fitness value and the value of the q quality parameter of the best match, or ( -1, 0 ) if no match was found.



 # for @l see above
 fitness_and_quality_parsed( text/html, @l )
 # ( 110, 0.7 )



    quality

Determines the quality (q) of a mime-type (passed as the first parameter) when compared against a media-range list string. F.ex.:



 quality( text/html, text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5 )
 # 0.7



    quality_parsed

Just like quality, except the second parameter must be pre-parsed by parse_media_range_list.

    best_match

Choose the mime-type with the highest quality (q) 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 HTTP Accept header. F.ex.:



 best_match( [ qw( application/xbel+xml text/xml ) ], text/*;q=0.5,*/*; q=0.1 )
 # text/xml



AUTHOR

Aristotle Pagaltzis <pagaltzis@gmx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Aristotle Pagaltzis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PARSE::MIME (3) 2015-01-10

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.