3 MIME::Type - Definition of one MIME type
8 my $mimetypes = MIME::Types->new;
9 my MIME::Type $plaintext = $mimetypes->type('text/plain');
10 print $plaintext->mediaType; # text
11 print $plaintext->subType; # plain
13 my @ext = $plaintext->extensions;
14 print "@ext" # txt asc c cc h hh cpp
16 print $plaintext->encoding # 8bit
17 if($plaintext->isBinary) # false
18 if($plaintext->isAscii) # true
19 if($plaintext->equals('text/plain') {...}
20 if($plaintext eq 'text/plain') # same
22 print MIME::Type->simplified('x-appl/x-zip') # 'appl/zip'
26 MIME types are used in MIME entities, for instance as part of e-mail
27 and HTTP traffic. Sometimes real knowledge about a mime-type is need.
28 Objects of C<MIME::Type> store the information on one such type.
30 This module is built to conform to the MIME types of RFC's 2045 and 2231.
31 It follows the official IANA registry at
32 F<http://www.iana.org/assignments/media-types/>
33 and the collection kept at F<http://www.ltsw.se/knbase/internet/mime.htp>
37 overload: B<string comparison>
41 When a MIME::Type object is compared to either a string or an other
42 MIME::TYpe, the L<equals()|MIME::Type/"Knowledge"> method is called. Comparison is smart,
43 which means that it extends common string comparison with some
44 features which are defined in the related RFCs.
48 overload: B<stringification>
52 The stringification (use of the object in a place where a string
53 is required) will result in the type name, the same as L<type()|MIME::Type/"Attributes">
56 example: use of stringification
58 my $mime = MIME::Type->new('text/html');
59 print "$mime\n"; # explicit stringification
60 print $mime; # implicit stringification
68 MIME::Type-E<gt>B<new>(OPTIONS)
72 Create (I<instantiate>) a new MIME::Type object which manages one
76 encoding <depends on type>
78 simplified <derived from type>
82 . encoding => '7bit'|'8bit'|'base64'|'quoted-printable'
86 How must this data be encoded to be transported safely. The default
87 depends on the type: mimes with as main type C<text/> will default
88 to C<quoted-printable> and all other to C<base64>.
92 . extensions => REF-ARRAY
96 An array of extensions which are using this mime.
100 . simplified => STRING
104 The mime types main- and sub-label can both start with C<x->, to indicate
105 that is a non-registered name. Of course, after registration this flag
106 can disappear which adds to the confusion. The simplified string has the
107 C<x-> thingies removed and are translated to lower-case.
115 Regular expression which defines for which systems this rule is valid. The
116 REGEX is matched on C<$^O>.
124 The type which is defined here. It consists of a I<type> and a I<sub-type>,
125 both case-insensitive. This module will return lower-case, but accept
134 $obj-E<gt>B<encoding>
138 Returns the type of encoding which is required to transport data of this
143 $obj-E<gt>B<extensions>
147 Returns a list of extensions which are known to be used for this
152 $obj-E<gt>B<simplified>([STRING])
154 MIME::Type-E<gt>B<simplified>([STRING])
158 Returns the simplified mime type for this object or the specified STRING.
159 Mime type names can get officially registered. Until then, they have to
160 carry an C<x-> preamble to indicate that. Of course, after recognition,
161 the C<x-> can disappear. In many cases, we prefer the simplified version
164 example: results of simplified()
166 my $mime = MIME::Type->new(type => 'x-appl/x-zip');
167 print $mime->simplified; # 'appl/zip'
168 print $mime->simplified('text/plain'); # 'text/plain'
169 print MIME::Type->simplified('x-xyz/x-abc'); # 'xyz/abc'
177 Returns the regular expression which can be used to determine whether this
178 type is active on the system where you are working on.
186 Returns the long type of this object, for instance C<'text/plain'>
192 $obj-E<gt>B<equals>(STRING|MIME)
196 Compare this mime-type object with a STRING or other object. In case of
197 a STRING, simplification will take place.
205 Returns false when the encoding is base64, and true otherwise. All encodings
206 except base64 are text encodings.
210 $obj-E<gt>B<isBinary>
214 Returns true when the encoding is base64.
218 $obj-E<gt>B<isRegistered>
222 Mime-types which are not registered by IANA nor defined in RFCs shall
223 start with an C<x->. This counts for as well the media-type as the
224 sub-type. In case either one of the types starts with C<x-> this
225 method will return false.
229 $obj-E<gt>B<isSignature>
233 Returns true when the type is in the list of known signatures.
237 $obj-E<gt>B<mediaType>
241 The media type of the simplified mime.
242 For C<'text/plain'> it will return C<'text'>.
244 For historical reasons, the C<'mainType'> method still can be used
245 to retreive the same value. However, that method is deprecated.
253 The sub type of the simplified mime.
254 For C<'text/plain'> it will return C<'plain'>.
260 Error: Type parameter is obligatory.
264 When a L<MIME::Type|MIME::Type> object is created, the type itself must be
265 specified with the C<type> option flag.
271 This module is part of MIME-Types distribution version 1.28,
272 built on September 07, 2009. Website: F<http://perl.overmeer.net/mimetypes/>
276 Copyrights 1999,2001-2009 by Mark Overmeer. For other contributors see ChangeLog.
278 This program is free software; you can redistribute it and/or modify it
279 under the same terms as Perl itself.
280 See F<http://www.perl.com/perl/misc/Artistic.html>