1MimeInfo(3) User Contributed Perl Documentation MimeInfo(3)
2
3
4
6 File::MimeInfo - Determine file type
7
9 use File::MimeInfo;
10 my $mime_type = mimetype($file);
11
13 This module can be used to determine the mime type of a file. It tries
14 to implement the freedesktop specification for a shared MIME database.
15
16 For this module shared-mime-info-spec 0.13 was used.
17
18 This package only uses the globs file. No real magic checking is used.
19 The File::MimeInfo::Magic package is provided for magic typing.
20
21 If you want to detemine the mimetype of data in a memory buffer you
22 should use File::MimeInfo::Magic in combination with IO::Scalar.
23
25 The method "mimetype" is exported by default. The methods "inodetype",
26 "globs", "extensions", "describe", "mimetype_canon" and "mimetype_isa"
27 can be exported on demand.
28
30 "new()"
31 Simple constructor to allow Object Oriented use of this module. If
32 you want to use this, include the package as "use File::MimeInfo
33 ();" to avoid importing sub "mimetype()".
34
35 "mimetype($file)"
36 Returns a mimetype string for $file, returns undef on failure.
37
38 This method bundles "inodetype" and "globs".
39
40 If these methods are unsuccessful the file is read and the mimetype
41 defaults to 'text/plain' or to 'application/octet-stream' when the
42 first ten chars of the file match ascii control chars (white spaces
43 excluded). If the file doesn't exist or isn't readable "undef" is
44 returned.
45
46 "inodetype($file)"
47 Returns a mimetype in the 'inode' namespace or undef when the file
48 is actually a normal file.
49
50 "globs($file)"
51 Returns a mimetype string for $file based on the filename and file‐
52 name extensions. Returns undef on failure. The file doesn't need
53 to exist.
54
55 Behaviour in list context (wantarray) is unspecified and will
56 change in future releases.
57
58 "extensions($mimetype)"
59 In list context, returns the list of filename extensions that map
60 to the given mimetype. In scalar context, returns the first exten‐
61 sion that is found in the database for this mimetype.
62
63 "describe($mimetype, $lang)"
64 Returns a description of this mimetype as supplied by the mime info
65 database. You can specify a language with the optional parameter
66 $lang, this should be the two letter language code used in the xml
67 files. Also you can set the global variable $File::MimeInfo::LANG
68 to specify a language.
69
70 This method returns undef when no xml file was found (i.e. the
71 mimetype doesn't exist in the database). It returns an empty string
72 when the xml file doesn't contain a description in the language you
73 specified.
74
75 Currently no real xml parsing is done, it trusts the xml files are
76 nicely formatted.
77
78 "mimetype_canon($mimetype)"
79 Returns the canonical mimetype for a given mimetype. Deprecated
80 mimetypes are typically aliased to their canonical variants. This
81 method only checks aliases, doesn't check whether the mimetype
82 exists.
83
84 Use this method as a filter when you take a mimetype as input.
85
86 "mimetype_isa($mimetype)"
87 "mimetype_isa($mimetype, $mimetype)"
88 When give only one argument this method returns a list with mime‐
89 types that are parent classes for this mimetype.
90
91 When given two arguments returns true if the second mimetype is a
92 parent class of the first one.
93
94 This method checks the subclasses table and applies a few rules for
95 implicite subclasses.
96
97 "rehash()"
98 Rehash the data files. Glob information is preparsed when this
99 method is called.
100
101 If you want to by-pass the XDG basedir system you can specify your
102 database directories by setting @File::MimeInfo::DIRS. But normally
103 it is better to change the XDG basedir environment variables.
104
105 "rehash_aliases()"
106 Rehashes the mime/aliases files.
107
108 "rehash_subclasses()"
109 Rehashes the mime/subclasses files.
110
112 This module throws an exception when it can't find any data files, when
113 it can't open a data file it found for reading or when a subroutine
114 doesn't get enough arguments. In the first case you either don't have
115 the freedesktop mime info database installed, or your environment vari‐
116 ables point to the wrong places, in the second case you have the data‐
117 base installed, but it is broken (the mime info database should logi‐
118 cally be world readable).
119
121 Make an option for using some caching mechanism to reduce init time.
122
123 Make "describe()" use real xml parsing ?
124
126 Perl versions prior to 5.8.0 do not have the ':utf8' IO Layer, thus for
127 the default method and for reading the xml files utf8 is not supported
128 for these versions.
129
130 Since it is not possible to distinguish between encoding types (utf8,
131 latin1, latin2 etc.) in a straightforward manner only utf8 is sup‐
132 ported (because the spec recommends this).
133
134 This module does not yet check extended attributes for a mimetype.
135 Patches for this are very welcome.
136
138 Please mail the author when you encounter any bugs.
139
141 Jaap Karssenberg ⎪⎪ Pardus [Larus] <pardus@cpan.org>
142
143 Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This pro‐
144 gram is free software; you can redistribute it and/or modify it under
145 the same terms as Perl itself.
146
148 File::BaseDir, File::MimeInfo::Magic, File::MimeInfo::Applications,
149 File::MimeInfo::Rox
150
151 related CPAN modules
152 File::MMagic
153
154 freedesktop specifications used
155 <http://freedesktop.org/wiki/Stan‐
156 dards_2fshared_2dmime_2dinfo_2dspec>, <http://freedesk‐
157 top.org/wiki/Standards_2fbasedir_2dspec>, <http://freedesk‐
158 top.org/wiki/Standards_2fdesktop_2dentry_2dspec>
159
160 freedesktop mime database
161 <http://freedesktop.org/wiki/Software_2fshared_2dmime_2dinfo>
162
163 other programs using this mime system
164 <http://rox.sourceforge.net>
165
166
167
168perl v5.8.8 2005-10-03 MimeInfo(3)