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

NAME

6       MIME::Type - Definition 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
31       This module is built to conform to the MIME types of RFC's 2045 and
32       2231.  It follows the official IANA registry at
33       http://www.iana.org/assignments/media-types/ and the collection kept at
34       http://www.ltsw.se/knbase/internet/mime.htp
35

OVERLOADED

37       overload: string comparison
38
39           When a MIME::Type object is compared to either a string or an other
40           MIME::TYpe, the equals() method is called.  Comparison is smart,
41           which means that it extends common string comparison with some fea‐
42           tures which are defined in the related RFCs.
43
44       overload: stringification
45
46           The stringification (use of the object in a place where a string is
47           required) will result in the type name, the same as type() returns.
48
49           Example: use of stringification
50
51            my $mime = MIME::Type->new('text/html');
52            print "$mime\n";   # explicit stringification
53            print $mime;       # implicit stringification
54

METHODS

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

DIAGNOSTICS

178       Error: Type parameter is obligatory.
179
180       When a MIME::Type object is created, the type itself must be specified
181       with the "type" option flag.
182

SEE ALSO

184       This module is part of MIME-Types distribution version 1.19, built on
185       March 25, 2007. Website: http://perl.overmeer.net/mimetypes/
186

LICENSE

188       Copyrights 1999,2001-2007 by Mark Overmeer.For other contributors see
189       ChangeLog.
190
191       This program is free software; you can redistribute it and/or modify it
192       under the same terms as Perl itself.  See
193       http://www.perl.com/perl/misc/Artistic.html
194
195
196
197perl v5.8.8                       2007-03-25                     MIME::Type(3)
Impressum