1File::MimeInfo(3)     User Contributed Perl Documentation    File::MimeInfo(3)
2
3
4

NAME

6       File::MimeInfo - Determine file type
7

SYNOPSIS

9         use File::MimeInfo;
10         my $mime_type = mimetype($file);
11

DESCRIPTION

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
24       This module loads the various data files when needed. If you want to
25       hash data ealier see the "rehash" methods below.
26

EXPORT

28       The method "mimetype" is exported by default.  The methods "inodetype",
29       "globs", "extensions", "describe", "mimetype_canon" and "mimetype_isa"
30       can be exported on demand.
31

METHODS

33       "new()"
34           Simple constructor to allow Object Oriented use of this module.  If
35           you want to use this, include the package as "use File::MimeInfo
36           ();" to avoid importing sub "mimetype()".
37
38       "mimetype($file)"
39           Returns a mimetype string for $file, returns undef on failure.
40
41           This method bundles "inodetype" and "globs".
42
43           If these methods are unsuccessful the file is read and the mimetype
44           defaults to 'text/plain' or to 'application/octet-stream' when the
45           first ten chars of the file match ascii control chars (white spaces
46           excluded).  If the file doesn't exist or isn't readable "undef" is
47           returned.
48
49       "inodetype($file)"
50           Returns a mimetype in the 'inode' namespace or undef when the file
51           is actually a normal file.
52
53       "globs($file)"
54           Returns a mimetype string for $file based on the filename and
55           filename extensions.  Returns undef on failure. The file doesn't
56           need to exist.
57
58           Behaviour in list context (wantarray) is unspecified and will
59           change in future releases.
60
61       "default($file)"
62           This method decides whether a file is binary or plain text by
63           looking at the first few bytes in the file. Used to decide between
64           "text/plain" and "application/octet-stream" if all other methods
65           have failed.
66
67           The spec states that we should check for the ascii control chars
68           and let higher bit chars pass to allow utf8. We try to be more
69           intelligent using perl utf8 support.
70
71       "extensions($mimetype)"
72           In list context, returns the list of filename extensions that map
73           to the given mimetype.  In scalar context, returns the first
74           extension that is found in the database for this mimetype.
75
76       "describe($mimetype, $lang)"
77           Returns a description of this mimetype as supplied by the mime info
78           database.  You can specify a language with the optional parameter
79           $lang, this should be the two letter language code used in the xml
80           files. Also you can set the global variable $File::MimeInfo::LANG
81           to specify a language.
82
83           This method returns undef when no xml file was found (i.e. the
84           mimetype doesn't exist in the database). It returns an empty string
85           when the xml file doesn't contain a description in the language you
86           specified.
87
88           Currently no real xml parsing is done, it trusts the xml files are
89           nicely formatted.
90
91       "mimetype_canon($mimetype)"
92           Returns the canonical mimetype for a given mimetype.  Deprecated
93           mimetypes are typically aliased to their canonical variants.  This
94           method only checks aliases, doesn't check whether the mimetype
95           exists.
96
97           Use this method as a filter when you take a mimetype as input.
98
99       "mimetype_isa($mimetype)"
100       "mimetype_isa($mimetype, $mimetype)"
101           When give only one argument this method returns a list with
102           mimetypes that are parent classes for this mimetype.
103
104           When given two arguments returns true if the second mimetype is a
105           parent class of the first one.
106
107           This method checks the subclasses table and applies a few rules for
108           implicite subclasses.
109
110       "rehash()"
111           Rehash the data files. Glob information is preparsed when this
112           method is called.
113
114           If you want to by-pass the XDG basedir system you can specify your
115           database directories by setting @File::MimeInfo::DIRS. But normally
116           it is better to change the XDG basedir environment variables.
117
118       "rehash_aliases()"
119           Rehashes the mime/aliases files.
120
121       "rehash_subclasses()"
122           Rehashes the mime/subclasses files.
123

DIAGNOSTICS

125       This module throws an exception when it can't find any data files, when
126       it can't open a data file it found for reading or when a subroutine
127       doesn't get enough arguments.  In the first case you either don't have
128       the freedesktop mime info database installed, or your environment
129       variables point to the wrong places, in the second case you have the
130       database installed, but it is broken (the mime info database should
131       logically be world readable).
132

TODO

134       Make an option for using some caching mechanism to reduce init time.
135
136       Make "describe()" use real xml parsing ?
137

LIMITATIONS

139       Perl versions prior to 5.8.0 do not have the ':utf8' IO Layer, thus for
140       the default method and for reading the xml files utf8 is not supported
141       for these versions.
142
143       Since it is not possible to distinguish between encoding types (utf8,
144       latin1, latin2 etc.)  in a straightforward manner only utf8 is
145       supported (because the spec recommends this).
146
147       This module does not yet check extended attributes for a mimetype.
148       Patches for this are very welcome.
149

BUGS

151       Please mail the author when you encounter any bugs.
152

AUTHOR

154       Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>
155
156       Copyright (c) 2003,2008 Jaap G Karssenberg. All rights reserved.  This
157       program is free software; you can redistribute it and/or modify it
158       under the same terms as Perl itself.
159

SEE ALSO

161       File::BaseDir, File::MimeInfo::Magic, File::MimeInfo::Applications,
162       File::MimeInfo::Rox
163
164       related CPAN modules
165           File::MMagic
166
167       freedesktop specifications used
168           http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec
169           <http://www.freedesktop.org/wiki/Specifications/shared-mime-info-
170           spec>, http://www.freedesktop.org/wiki/Specifications/basedir-spec
171           <http://www.freedesktop.org/wiki/Specifications/basedir-spec>,
172           http://www.freedesktop.org/wiki/Specifications/desktop-entry-spec
173           <http://www.freedesktop.org/wiki/Specifications/desktop-entry-spec>
174
175       freedesktop mime database
176           http://www.freedesktop.org/wiki/Software/shared-mime-info
177           <http://www.freedesktop.org/wiki/Software/shared-mime-info>
178
179
180
181perl v5.12.0                      2010-05-01                 File::MimeInfo(3)
Impressum