Web::MIME::Type
MIME type object
SYNOPSIS
use Web::MIME::Type;
my $type = Web::MIME::Type->parse_web_mime_type
('text/CSS; charset="US-ASCII"');
is $type->type, 'text';
is $type->subtype, 'css';
is $type->mime_type_portion, 'text/css';
is_deeply $type->attrs, ['charset'];
is $type->param ('charset'), 'US-ASCII';
$type->param (charset => 'utf-8');
is $type->param ('charset'), 'utf-8';
is $type->as_valid_mime_type, 'text/css; charset=us-ascii';
is $type->as_valid_mime_type_with_no_params, 'text/css';
DESCRIPTION
The Web::MIME::Type
class is used for MIME type record, which represents a MIME type (aka Internet Media Type) string, with or without parameters.
Please note that, for compatibility with previous versions of this module, a Web::MIME::Type object can represent a MIME type record that cannot be serialized into a valid MIME type (e.g. a MIME type whose subtype is the empty string). Such MIME types are referred to as ill-formed in this documentation.
METHODS
Following methods are available:
$t = Web::MIME::Type->new_from_type_and_subtype ($type, $subtype)
-
Returns a new object whose type is $type (string) and subtype is $subtype (string). $type and $subtype are ASCII case-insensitive.
Please note that the result object might be invalid.
$type = $t->type ([$type])
-
On getting, it returns the
type
part of the MIME type, in lowercase. Thetype
part does not containsubtype
.On setting, it updates the
type
part of the MIME type. Note that thetype
is ASCII case-insensitive and therefore normalized by the setter.Please note that the setter might make the object invalid.
$subtype = $t->subtype ([$subtype])
-
On getting, it returns the
subtype
part of the MIME type, in lowercase.On setting, it updates the
subtype
part of the MIME type. Note that thesubtype
is ASCII case-insensitive and therefore normalized by the setter.Please note that the setter might make the object invalid.
$string = $mime->mime_type_portion
-
Return the essense (formerly known as MIME type portion) of the object, i.e. the "type/subtype" part of the MIME type (without parameter), in lowercase. The result is a character string.
If the object is invalid, the result might not be a valid MIME type.
[$string, $string, ...] = $mime->attrs
-
Return a reference to a new array that contains the keys of the parameters of the object (i.e. the list of the parameter names in lowercase, in the order of additions). The array items are character strings.
$s = $t->param ($attr, [$value])
-
If there is only an argument, $attr, then the method returns the value of the
parameter
whoseattribute
matches to $attr. Note thatattribute
is ASCII case-insensitive. If there is no suchparameter
, thenundef
is returned.Note that the object does not distinguish whether the value is represented as a
token
or aquoted-string
in the lexical form. Therefore, the method never returnes enclosing"
characters nor\
inquoted-pair
.If there are two arguments, the method sets the value of the
parameter
whoesattribute
matches to $attr to $value. If the parameter already exists, the previous value is discarded. Please note that the method might make the object invalid. $boolean = $t->apache_bug
-
Return whether the "check-for-apache-bug flag" [MIMESNIFF] is set or not.
BOOL = $t->is_javascript
-
Returns whether the type represents JavaScript or not.
BOOL = $t->is_scripting_lang
-
Returns whether the type represents a scripting language (typically run within the Web browser's environment), such as JavaScript.
BOOL = $t->is_styling_lang
-
Returns whether the type represents a styling language, such as CSS.
$boolean = $t->is_image
-
Return whether the MIME type is an image type [MIMESNIFF] or not.
$boolean = $t->is_audio_or_video
-
Return whether the MIME type is an audio or video type [MIMESNIFF] or not.
BOOL = $t->is_text_based
-
Returns whether the type represents a text-based format.
BOOL = $t->is_composed_type
-
Returns whether the
type
is a composed type, i.e.message
ormultipart
. BOOL = $t->is_xml_mime_type
-
Returns whether the type is an XML MIME type according to Web Applications 1.0's definition.
$string = $mime->as_valid_mime_type_with_no_params
-
Serialize the object as a valid MIME type string with no parameters in lowercase. The result is a character string. If the object is invalid,
undef
is returned instead. $string = $mime->as_valid_mime_type
-
Serialize the object as a valid MIME type string. The result is a character string. If the object is invalid,
undef
is returned instead.For non-invalid case the method is an implementation of the "serialize a MIME type" operation of the MIME Sniffing Standard.
$t->validate ($onerror, no_required_params => BOOL)
-
Performs conformance checking of the object. It reports errors or wanrings such as "unregistered type error" or "private subtype warning" to the code reference, $onerror.
If the
no_required_params
parameter is set to true, it does not report errors on required parameters.
SEE ALSO
HISTORY
This module derived from the Message::MIME::Type module in the manakai-core package <https://github.com/wakaba/manakai>
.
Part of this module is originally contained in the Whatpm::IMTChecker module. The Whatpm::IMTChecker module is obsolete and removed from the manakai package in favor of the Message::MIME::Type module.
SPECIFICATIONS
- MIME
-
RFC 2048, Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types
<https://tools.ietf.org/html/rfc2046>
. - HTTP
-
RFC 7230, Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
<https://tools.ietf.org/html/rfc7230>
. - MIMESNIFF
-
MIME Sniffing Standard
<https://mimesniff.spec.whatwg.org/>
. - MTREG
-
RFC 4288, Media Type Specifications and Registration Procedures
<https://tools.ietf.org/html/rfc4288>
. - XMLMT
-
RFC 7303, XML Media Types
<https://tools.ietf.org/html/rfc7303>
. - IANAREG
-
MIME Media Types
<https://www.iana.org/assignments/media-types/>
.
AUTHOR
Wakaba <wakaba@suikawiki.org>.
LICENSE
Copyright 2007-2018 Wakaba <wakaba@suikawiki.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.