++ed by:

2 PAUSE users
5 non-PAUSE users.

Jaap Karssenberg


File::MimeInfo - Determine file type


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


This module can be used to determine the mime type of a file. It tries to implement the freedesktop specification for a shared MIME database.

For this module shared-mime-info-spec 0.12 was used.

This packege only uses the globs file. No real magic checking is used. The File::MimeInfo::Magic package is provided for magic typing.


The method mimetype is exported by default. The methods inodetype, globs and describe can be exported on demand.



Simple constructor to allow Object Oriented use of this module. If you want to use this, use the package as use File::MimeInfo (); to avoid importing sub mimetype.


Returns a mime-type string for $file, returns undef on failure.

This method bundles inodetype and globs.

If these methods are unsuccessfull the file is read and the mime-type defaults to 'text/plain' or to 'application/octet-stream' when the first ten chars of the file match ascii control chars (white spaces excluded). If the file doesn't exist or isn't readable undef is returned.


Returns a mimetype in the 'inode' namespace or undef when the file is actually a normal file.


Returns a mime-type string for $file based on the glob rules, returns undef on failure. The file doesn't need to exist.


Returns a description of this mimetype as supplied by the mime info database. You can set the global variable $File::MimeInfo::LANG to specify a language, this should be the two letter language code used in the xml files. Returns undef when there seems to be no xml file for this mimetype, this could very well mean the mimetype doesn't exist, it could also mean that the language you specified wasn't found.

Currently no real xml parsing is done, it trust the xml files are nicely formatted.


Rehash the data files. Glob information is preparsed when this method is called.


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


Make an option for using some caching mechanism to reduce init time.

Make "describe" do real xml parsing ?

Make Base Dir Spec stuff separate module ?


Perl versions prior to 5.8.0 do not have the ':utf8' IO Layer, thus for the default method and for reading the xml files utf8 is not supported for these versions.

Please mail the author when you encounter any other bugs.


Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>

Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.




freedesktop specifications used

http://www.freedesktop.org/standards/shared-mime-info-spec/, http://www.freedesktop.org/standards/basedir-spec/

freedesktop mime database


other programs using this mime system


1 POD Error

The following errors were encountered while parsing the POD:

Around line 260:

=over without closing =back