Skip to content

Commit

Permalink
reflow and de-boilerplate the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ap committed Jan 5, 2015
1 parent 5f55fcf commit 87e26f4
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions lib/Parse/MIME.pm
Expand Up @@ -128,77 +128,77 @@ __END__
=head1 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: L<http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1>
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:
L<http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1>
=head1 INTERFACE
None of the following functions are exported by default. You can use the C<:all> tag to import all of them into your package:
None of the following functions are exported by default. You can use the
C<:all> tag to import all of them into your package:
use Parse::MIME ':all';
=head2 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:
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 } )
=head2 parse_media_range
Media-ranges are mime-types with wild-cards and a C<q> quality parameter. This function works just like L</parse_mime_type>, but also guarantees that there is a value for C<q> in the params hash, supplying the default value if necessary.
Media-ranges are mime-types with wild-cards and a C<q> quality parameter. This
function works just like L</parse_mime_type>, but also guarantees that there is
a value for C<q> in the params hash, supplying the default value if necessary.
parse_media_range 'application/xhtml'
# ( 'application', 'xhtml', { q => 1 } )
=head2 parse_media_range_list
Media-range lists are comma-separated lists of media ranges. This function works just like L</parse_media_range>, but accepts a list of media ranges and returns for all of media-ranges.
Media-range lists are comma-separated lists of media ranges. This function
works just like L</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 } )
=head2 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> (passed as a flat list). Returns the fitness value and the value of the C<q> quality parameter of the best match, or C<( -1, 0 )> if no match was found.
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> (passed as a flat list). Returns the fitness value and
the value of the C<q> quality parameter of the best match, or C<( -1, 0 )> if
no match was found.
# for @l see above
fitness_and_quality_parsed( 'text/html', @l )
# ( 110, 0.7 )
=head2 quality
Determines the quality (C<q>) of a mime-type (passed as the first parameter) when compared against a media-range list string. F.ex.:
Determines the quality (C<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
=head2 quality_parsed
Just like L</quality>, except the second parameter must be pre-parsed by L</parse_media_range_list>.
Just like L</quality>, except the second parameter must be pre-parsed by
L</parse_media_range_list>.
=head2 best_match
Choose the mime-type with the highest quality (C<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 C<Accept> header. F.ex.:
Choose the mime-type with the highest quality (C<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 C<Accept> header. F.ex.:
best_match( [ qw( application/xbel+xml text/xml ) ], 'text/*;q=0.5,*/*; q=0.1' )
# 'text/xml'
=head1 AUTHOR
=over 4
=item * Joe Gregorio L<mailto:joe@bitworking.org>
Original Python code
=item * Aristotle Pagaltzis L<mailto:pagaltzis@gmx.de>
Perl port
=back
=head1 COPYRIGHT AND LICENCE
Documentation: Copyright (c) 2008, Joe Gregorio. All rights reserved.
Perl code: Copyright (c) 2008, Aristotle Pagaltzis. All rights reserved.

0 comments on commit 87e26f4

Please sign in to comment.