1MIME::Types(3) User Contributed Perl Documentation MIME::Types(3)
2
3
4
6 MIME::Types - Definition of MIME types
7
9 MIME::Types
10 is a Exporter
11
13 use MIME::Types;
14 my $mimetypes = MIME::Types->new;
15 my MIME::Type $plaintext = $mimetypes->type('text/plain');
16 my MIME::Type $imagegif = $mimetypes->mimeTypeOf('gif');
17
19 MIME types are used in MIME compliant lines, for instance as part of
20 e-mail and HTTP traffic, to indicate the type of content which is
21 transmitted. Sometimes real knowledge about a mime-type is need.
22
23 This module maintains a set of MIME::Type objects, which each describe
24 one known mime type. There are many types defined by RFCs and vendors,
25 so the list is long but not complete. Please don't hestitate to ask to
26 add additional information.
27
28 If you wish to get access to the "mime.types" files, which are
29 available on various places in UNIX and Linux systems, then have a look
30 at File::TypeInfo.
31
33 Instantiation
34 MIME::Types->new(OPTIONS)
35
36 Create a new "MIME::Types" object which manages the data. In the
37 current implementation, it does not matter whether you create this
38 object often within your program, but in the future this may
39 change.
40
41 Option --Default
42 only_complete <false>
43
44 . only_complete => BOOLEAN
45
46 Only include complete MIME type definitions: requires at least
47 one known extension. This will reduce the number of entries
48 --and with that the amount of memory consumed-- considerably.
49
50 In your program you have to decide: the first time that you
51 call the creator ("new") determines whether you get the full or
52 the partial information.
53
54 Knowledge
55 $obj->addType(TYPE, ...)
56
57 Add one or more TYPEs to the set of known types. Each TYPE is a
58 "MIME::Type" which must be experimental: either the main-type or
59 the sub-type must start with "x-".
60
61 Please inform the maintainer of this module when registered types
62 are missing. Before version MIME::Types version 1.14, a warning
63 was produced when an unknown IANA type was added. This has been
64 removed, because some people need that to get their application to
65 work locally... broken applications...
66
67 $obj->extensions
68
69 Returns a list of all defined extensions.
70
71 $obj->mimeTypeOf(FILENAME)
72
73 Returns the "MIME::Type" object which belongs to the FILENAME (or
74 simply its filename extension) or "undef" if the file type is
75 unknown. The extension is used, and considered case-insensitive.
76
77 In some cases, more than one type is known for a certain filename
78 extension. In that case, one of the alternatives is chosen at
79 random.
80
81 example: use of mimeTypeOf()
82
83 my MIME::Types $types = MIME::Types->new;
84 my MIME::Type $mime = $types->mimeTypeOf('gif');
85
86 my MIME::Type $mime = $types->mimeTypeOf('jpg');
87 print $mime->isBinary;
88
89 $obj->type(STRING)
90
91 Return the "MIME::Type" which describes the type related to STRING.
92 One type may be described more than once. Different extensions is
93 use for this type, and different operating systems may cause more
94 than one "MIME::Type" object to be defined. In scalar context,
95 only the first is returned.
96
97 $obj->types
98
99 Returns a list of all defined mime-types
100
102 The next functions are provided for backward compatibility with
103 MIME::Types versions 0.06 and below. This code originates from Jeff
104 Okamoto okamoto@corp.hp.com and others.
105
106 by_mediatype(TYPE)
107
108 This function takes a media type and returns a list or anonymous
109 array of anonymous three-element arrays whose values are the file
110 name suffix used to identify it, the media type, and a content
111 encoding.
112
113 TYPE can be a full type name (contains '/', and will be matched in
114 full), a partial type (which is used as regular expression) or a
115 real regular expression.
116
117 by_suffix(FILENAME|SUFFIX)
118
119 Like "mimeTypeOf", but does not return an "MIME::Type" object. If
120 the file +type is unknown, both the returned media type and
121 encoding are empty strings.
122
123 example: use of function by_suffix()
124
125 use MIME::Types 'by_suffix';
126 my ($mediatype, $encoding) = by_suffix 'image.gif';
127
128 my $refdata = by_suffix 'image.gif';
129 my ($mediatype, $encoding) = @$refdata;
130
131 import_mime_types
132
133 This method has been removed: mime-types are only useful if
134 understood by many parties. Therefore, the IANA assigns names
135 which can be used. In the table kept by this "MIME::Types" module
136 all these names, plus the most often used termporary names are
137 kept. When names seem to be missing, please contact the maintainer
138 for inclussion.
139
141 This module is part of MIME-Types distribution version 1.28, built on
142 September 07, 2009. Website: http://perl.overmeer.net/mimetypes/
143
145 Copyrights 1999,2001-2009 by Mark Overmeer. For other contributors see
146 ChangeLog.
147
148 This program is free software; you can redistribute it and/or modify it
149 under the same terms as Perl itself. See
150 http://www.perl.com/perl/misc/Artistic.html
151
152
153
154perl v5.12.0 2009-09-06 MIME::Types(3)