1MIME::Type(3)         User Contributed Perl Documentation        MIME::Type(3)
2
3
4

NAME

6       MIME::Type - description of one MIME type
7

SYNOPSIS

9        use MIME::Types;
10        my $mimetypes = MIME::Types->new;
11        my MIME::Type $plaintext = $mimetypes->type('text/plain');
12        print $plaintext->mediaType;   # text
13        print $plaintext->subType;     # plain
14
15        my @ext = $plaintext->extensions;
16        print "@ext"                   # txt asc c cc h hh cpp
17
18        print $plaintext->encoding     # 8bit
19        if($plaintext->isBinary)       # false
20        if($plaintext->isAscii)        # true
21        if($plaintext->equals('text/plain') {...}
22        if($plaintext eq 'text/plain') # same
23
24        print MIME::Type->simplified('x-appl/x-zip') #  'appl/zip'
25

DESCRIPTION

27       MIME types are used in MIME entities, for instance as part of e-mail
28       and HTTP traffic.  Sometimes real knowledge about a mime-type is need.
29       Objects of "MIME::Type" store the information on one such type.
30

OVERLOADED

32       overload: string comparison
33           When a MIME::Type object is compared to either a string or another
34           MIME::TYpe, the equals() method is called.  Comparison is smart,
35           which means that it extends common string comparison with some
36           features which are defined in the related RFCs.
37
38       overload: stringification
39           The stringification (use of the object in a place where a string is
40           required) will result in the type name, the same as type() returns.
41
42           example: use of stringification
43
44            my $mime = MIME::Type->new('text/html');
45            print "$mime\n";   # explicit stringification
46            print $mime;       # implicit stringification
47

METHODS

49   Initiation
50       MIME::Type->new(%options)
51           Create (instantiate) a new MIME::Type object which manages one mime
52           type.
53
54            -Option    --Default
55             encoding    <depends on type>
56             extensions  []
57             simplified  <derived from type>
58             system      undef
59             type        <required>
60
61           encoding => '7bit'|'8bit'|'base64'|'quoted-printable'
62             How must this data be encoded to be transported safely.  The
63             default depends on the type: mimes with as main type "text/" will
64             default to "quoted-printable" and all other to "base64".
65
66           extensions => REF-ARRAY
67             An array of extensions which are using this mime.
68
69           simplified => STRING
70             The mime types main- and sub-label can both start with "x-", to
71             indicate that is a non-registered name.  Of course, after
72             registration this flag can disappear which adds to the confusion.
73             The simplified string has the "x-" thingies removed and are
74             translated to lower-case.
75
76           system => REGEX
77             Regular expression which defines for which systems this rule is
78             valid.  The REGEX is matched on $^O.
79
80           type => STRING
81             The type which is defined here.  It consists of a type and a sub-
82             type, both case-insensitive.  This module will return lower-case,
83             but accept upper-case.
84
85   Attributes
86       $obj->encoding()
87           Returns the type of encoding which is required to transport data of
88           this type safely.
89
90       $obj->extensions()
91           Returns a list of extensions which are known to be used for this
92           mime type.
93
94       $obj->simplified( [$string] )
95       MIME::Type->simplified( [$string] )
96           Returns the simplified mime type for this object or the specified
97           STRING.  Mime type names can get officially registered.  Until
98           then, they have to carry an "x-" preamble to indicate that.  Of
99           course, after recognition, the "x-" can disappear.  In many cases,
100           we prefer the simplified version of the type.
101
102           example: results of simplified()
103
104            my $mime = MIME::Type->new(type => 'x-appl/x-zip');
105            print $mime->simplified;                     # 'appl/zip'
106
107            print $mime->simplified('text/PLAIN');       # 'text/plain'
108            print MIME::Type->simplified('x-xyz/x-abc'); # 'xyz/abc'
109
110       $obj->system()
111           Returns the regular expression which can be used to determine
112           whether this type is active on the system where you are working on.
113
114       $obj->type()
115           Returns the long type of this object, for instance 'text/plain'
116
117   Knowledge
118       $obj->equals($string|$mime)
119           Compare this mime-type object with a STRING or other object.  In
120           case of a STRING, simplification will take place.
121
122       $obj->isAscii()
123           Old name for isText().
124
125       $obj->isBinary()
126           Returns true when the type is not known to be text.  See isText().
127
128       $obj->isExperimental()
129           [2.00] Return "true" when the type is defined for experimental use;
130           the subtype starts with "x."
131
132       $obj->isPersonal()
133           [2.00] Return "true" when the type is defined by a person for
134           private use; the subtype starts with "prs."
135
136       $obj->isRegistered()
137           Mime-types which are not registered by IANA nor defined in RFCs
138           shall start with an "x-".  This counts for as well the media-type
139           as the sub-type.  In case either one of the types starts with "x-"
140           this method will return false.
141
142       $obj->isSignature()
143           Returns true when the type is in the list of known signatures.
144
145       $obj->isText()
146           [2.05] All types which may have the charset attribute, are text.
147           However, there is currently no record of attributes in this
148           module... so we guess.
149
150       $obj->isVendor()
151           [2.00] Return "true" when the type is defined by a vendor; the
152           subtype starts with "vnd."
153
154       $obj->mediaType()
155           The media type of the simplified mime.  For 'text/plain' it will
156           return 'text'.
157
158           For historical reasons, the 'mainType' method still can be used to
159           retrieve the same value.  However, that method is deprecated.
160
161       $obj->subType()
162           The sub type of the simplified mime.  For 'text/plain' it will
163           return 'plain'.
164

DIAGNOSTICS

166       Error: Type parameter is obligatory.
167           When a MIME::Type object is created, the type itself must be
168           specified with the "type" option flag.
169

SEE ALSO

171       This module is part of MIME-Types distribution version 2.17, built on
172       January 26, 2018. Website: http://perl.overmeer.net/CPAN/
173

LICENSE

175       Copyrights 1999-2018 by [Mark Overmeer <markov@cpan.org>]. For other
176       contributors see ChangeLog.
177
178       This program is free software; you can redistribute it and/or modify it
179       under the same terms as Perl itself.  See http://dev.perl.org/licenses/
180
181
182
183perl v5.32.0                      2020-07-28                     MIME::Type(3)
Impressum