File::MimeInfo - Guess file type by extension
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.11 and basedir-spec 0.5 where used.
Currently only the globs file is used. No real magic checking is used. This is because the goal was to make a module that would share filetypes with rox, the current rox implementation also only uses globs.
( See "SEE ALSO" for url's )
The method mimetype is exported by default.
mimetype
new()
Simple constructor to allow Object Oriented use of this module.
mimetype($file)
Returns a mime-type string for $file, returns undef on failure. Since currently only globs are supported, the file doesn't need to exist.
$file
dirs()
Lists all directories that would be scanned when rehashing, they don't need to exist or need have a "mime" subdir.
The default behaviour can be overloaded by setting global variable @DIRS, this is mainly used for testing purposes.
@DIRS
It lists the least important dir first.
rehash()
Rehash the data files. Glob information is preparsed
This module uses the following two environment variables when looking for available data file.
Quoting basedir-spec 0.5 :
Defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share is used.
$XDG_DATA_HOME
$HOME/.local/share
Mime data could be found in $XDG_DATA_HOME/mime.
$XDG_DATA_HOME/mime
Defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be seperated with a colon ':'. If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should is used.
$XDG_DATA_DIRS
/usr/local/share/:/usr/share/
Mime data could be found in the "mime" subdirs of these dirs.
The order of base directories denotes their importance; the first directory listed is the most important. When the same information is defined in multiple places the information defined relative to the more important base directory takes precedent. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS.
This module throws a warning if it couldn't find any data files. This can either mean that you don't have the freedesktop mime info database installed, or your environment variables point to the wrong places.
An exception is thrown when it can't open a data file it found. This should never happen, since the mime info should logically be world readable.
Jaap Karssenberg || Pardus [Larus] <j.g.karssenberg@student.utwente.nl>
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.
File::MMagic
http://www.freedesktop.org/standards/shared-mime-info-spec/, http://www.freedesktop.org/standards/basedir-spec/
http://www.freedesktop.org/software/shared-mime-info/
http://rox.sourceforge.net
1 POD Error
The following errors were encountered while parsing the POD:
=over without closing =back
To install File::MimeInfo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::MimeInfo
CPAN shell
perl -MCPAN -e shell install File::MimeInfo
For more information on module installation, please visit the detailed CPAN module installation guide.