Create a new MIME::Types object which manages the data. In the current
implementation, it does not matter whether you create this object often
within your program, but in the future this may change.
$obj-><B>addTypeB>($type, ...) Add one or more TYPEs to the set of known types. Each TYPE is a MIME::Type which must be experimental: either the main-type or the sub-type must start with x-.
Please inform the maintainer of this module when registered types are missing. Before version MIME::Types version 1.14, a warning was produced when an unknown IANA type was added. This has been removed, because some people need that to get their application to work locally... broken applications...
$obj-><B>extensionsB>() Returns a list of all defined extensions. $obj-><B>listTypesB>() Returns a list of all defined mime-types by name only. This will <B>notB> instantiate MIME::Type objects. See types() $obj-><B>mimeTypeOfB>($filename) Returns the MIME::Type object which belongs to the FILENAME (or simply its filename extension) or undef if the file type is unknown. The extension is used and considered case-insensitive.
In some cases, more than one type is known for a certain filename extension. In that case, the preferred one is taken (for an unclear definition of preference)
example: use of mimeTypeOf()
my $types = MIME::Types->new; my $mime = $types->mimeTypeOf(gif); my $mime = $types->mimeTypeOf(picture.jpg); print $mime->isBinary;
$obj-><B>typeB>($string) Returns the MIME::Type which describes the type related to STRING. [2.00] Only one type will be returned.
[before 2.00] One type may be described more than once. Different extensions may be in use for this type, and different operating systems may cause more than one MIME::Type object to be defined. In scalar context, only the first is returned.
$obj-><B>typesB>() Returns a list of all defined mime-types. For reasons of backwards compatibility, this will instantiate MIME::Type objects, which will be returned. See listTypes().
$obj-><B>httpAcceptB>($header) [2.07] Decompose a typical HTTP-Accept header, and sort it based on the included priority information. Returned is a sorted list of type names, where the highest priority type is first. The list may contain */* (accept any) or a * as subtype.
Ill-formated typenames are ignored. On equal qualities, the order is kept. See RFC2616 section 14.1
my @types = $types->httpAccept(text/html, application/json;q=0.9);
$obj-><B>httpAcceptBestB>($accept|\@types, @have) [2.07] The $accept string is processed via httpAccept() to order the types on preference. You may also provide a list of ordered @types which may have been the result of that method, called earlier.
As second parameter, you pass a LIST of types you @have to offer. Those need to be MIME::Type objects. The preferred type will get selected. When none of these are accepted by the client, this will return undef. It should result in a 406 server response.
my $accept = $req->header(Accept); my @have = map $mt->type($_), qw[text/plain text/html]; my @ext = $mt->httpAcceptBest($accept, @have);
$obj-><B>httpAcceptSelectB>($accept|\@types, @filenames|\@filenames) [2.07] Like httpAcceptBest(), but now we do not return a pair with mime-type and filename, not just the type. If $accept is undef, the first filename is returned.
use HTTP::Status :constants; use File::Glob bsd_glob; # understands blanks in filename my @filenames = bsd_glob "$imagedir/$fnbase.*; my $accept = $req->header(Accept); my ($fn, $mime) = $mt->httpAcceptSelect($accept, @filenames); my $code = defined $mime ? HTTP_NOT_ACCEPTABLE : HTTP_OK;
The next functions are provided for backward compatibility with MIME::Types versions [0.06] and below. This code originates from Jeff Okamoto firstname.lastname@example.org and others.
<B>by_mediatypeB>(TYPE) This function takes a media type and returns a list or anonymous array of anonymous three-element arrays whose values are the file name suffix used to identify it, the media type, and a content encoding.
TYPE can be a full type name (contains /, and will be matched in full), a partial type (which is used as regular expression) or a real regular expression.
<B>by_suffixB>(FILENAME|SUFFIX) Like mimeTypeOf, but does not return an MIME::Type object. If the file +type is unknown, both the returned media type and encoding are empty strings.
example: use of function by_suffix()
<B>import_mime_typesB>() This method has been removed: mime-types are only useful if understood by many parties. Therefore, the IANA assigns names which can be used. In the table kept by this MIME::Types module all these names, plus the most often used temporary names are kept. When names seem to be missing, please contact the maintainer for inclusion.
This module is part of MIME-Types distribution version 2.13, built on March 07, 2016. Website: http://perl.overmeer.net/mimetypes/
Copyrights 1999,2001-2016 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
|perl v5.20.3||MIME::TYPES (3)||2016-03-07|