1MIME::Type(3) User Contributed Perl Documentation MIME::Type(3)
2
3
4
6 MIME::Type - Definition of one MIME type
7
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
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
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
42 features 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
56 Initiation
57 MIME::Type->new(OPTIONS)
58
59 Create (instantiate) a new MIME::Type object which manages one mime
60 type.
61
62 Option --Default
63 encoding <depends on type>
64 extensions []
65 simplified <derived from type>
66 system undef
67 type <required>
68
69 . encoding => '7bit'|'8bit'|'base64'|'quoted-printable'
70
71 How must this data be encoded to be transported safely. The
72 default depends on the type: mimes with as main type "text/"
73 will default to "quoted-printable" and all other to "base64".
74
75 . extensions => REF-ARRAY
76
77 An array of extensions which are using this mime.
78
79 . simplified => STRING
80
81 The mime types main- and sub-label can both start with "x-", to
82 indicate that is a non-registered name. Of course, after
83 registration this flag can disappear which adds to the
84 confusion. The simplified string has the "x-" thingies removed
85 and are translated to lower-case.
86
87 . system => REGEX
88
89 Regular expression which defines for which systems this rule is
90 valid. The REGEX is matched on $^O.
91
92 . type => STRING
93
94 The type which is defined here. It consists of a type and a
95 sub-type, both case-insensitive. This module will return
96 lower-case, but accept upper-case.
97
98 Attributes
99 $obj->encoding
100
101 Returns the type of encoding which is required to transport data of
102 this type safely.
103
104 $obj->extensions
105
106 Returns a list of extensions which are known to be used for this
107 mime type.
108
109 $obj->simplified([STRING])
110
111 MIME::Type->simplified([STRING])
112
113 Returns the simplified mime type for this object or the specified
114 STRING. Mime type names can get officially registered. Until
115 then, they have to carry an "x-" preamble to indicate that. Of
116 course, after recognition, the "x-" can disappear. In many cases,
117 we prefer the simplified version of the type.
118
119 example: results of simplified()
120
121 my $mime = MIME::Type->new(type => 'x-appl/x-zip');
122 print $mime->simplified; # 'appl/zip'
123 print $mime->simplified('text/plain'); # 'text/plain'
124 print MIME::Type->simplified('x-xyz/x-abc'); # 'xyz/abc'
125
126 $obj->system
127
128 Returns the regular expression which can be used to determine
129 whether this type is active on the system where you are working on.
130
131 $obj->type
132
133 Returns the long type of this object, for instance 'text/plain'
134
135 Knowledge
136 $obj->equals(STRING|MIME)
137
138 Compare this mime-type object with a STRING or other object. In
139 case of a STRING, simplification will take place.
140
141 $obj->isAscii
142
143 Returns false when the encoding is base64, and true otherwise. All
144 encodings except base64 are text encodings.
145
146 $obj->isBinary
147
148 Returns true when the encoding is base64.
149
150 $obj->isRegistered
151
152 Mime-types which are not registered by IANA nor defined in RFCs
153 shall start with an "x-". This counts for as well the media-type
154 as the sub-type. In case either one of the types starts with "x-"
155 this method will return false.
156
157 $obj->isSignature
158
159 Returns true when the type is in the list of known signatures.
160
161 $obj->mediaType
162
163 The media type of the simplified mime. For 'text/plain' it will
164 return 'text'.
165
166 For historical reasons, the 'mainType' method still can be used to
167 retreive the same value. However, that method is deprecated.
168
169 $obj->subType
170
171 The sub type of the simplified mime. For 'text/plain' it will
172 return 'plain'.
173
175 Error: Type parameter is obligatory.
176
177 When a MIME::Type object is created, the type itself must be
178 specified with the "type" option flag.
179
181 This module is part of MIME-Types distribution version 1.28, built on
182 September 07, 2009. Website: http://perl.overmeer.net/mimetypes/
183
185 Copyrights 1999,2001-2009 by Mark Overmeer. For other contributors see
186 ChangeLog.
187
188 This program is free software; you can redistribute it and/or modify it
189 under the same terms as Perl itself. See
190 http://www.perl.com/perl/misc/Artistic.html
191
192
193
194perl v5.12.0 2009-09-06 MIME::Type(3)