NAME

    MIME::Detect - MIME file type identification

TO DO

    before release:

    * Revisit API compatibility with other MimeInfo modules

    * Write updater for easier updating the distributed XML file. Maybe
    that's just an appropriate invocation of git clone or lwp-mirror from
    https://cgit.freedesktop.org/xdg/shared-mime-info/plain/freedesktop.org
    .xml.in (nasty, I know).

    * Make mime-info.pl commandline compatible with file

SYNOPSIS

      my $mime = MIME::Detect->new();
    
      for my $file (@ARGV) {
        print sprintf "%s: %s\n", $file, $_->mime_type
            for $mime->mime_types($file);
      };

METHODS

 MIME::Detect->new( ... )

      my $mime = MIME::Detect->new();

    Creates a new instance and reads the database distributed with this
    module.

      my $mime = MIME::Detect->new(
          files => [
              '/usr/share/freedesktop.org/mimeinfo.xml',
              't/mimeinfo.xml',
          ],
      );

 $mime->read_database %options

      $mime->read_database(
          xml => MIME::Detect::FreedesktopOrgDB->get_xml,
          files => [
              'mymime/mymime.xml',
              '/usr/share/freedesktop.org/mime.xml',
          ],
      );

    If you want rules in addition to the default database included with the
    distribution, you can load the rules from another file. Passing in
    multiple filenames will join the multiple databases. Duplicate file
    type definitions will not be detected and will be returned as
    duplicates.

    The rules will be sorted according to the priority specified in the
    database file(s).

    By default, the XML database stored alongside
    MIME::Detect::FreedesktopOrgDB will be loaded after all custom files
    have been loaded. To pass in a different fallback database, either pass
    in a reference to the XML string or the name of a package that has an
    get_xml subroutine.

    To prevent loading the default database, pass undef for the xml key.

 $mime->mime_types

        my @types = $mime->mime_types( 'some/file' );
        for( @types ) {
            print $type->mime_type, "\n";
        };

    Returns the list of MIME types according to their likelyhood. The first
    type is the most likely.

 $mime->mime_type

        my $type = $mime->mime_type( 'some/file' );
        print $type->mime_type, "\n"
            if $type;

    Returns the most likely type of a file. Returns undef if no file type
    can be determined.

NAME

    MIME::Detect::Type - the type of a file

SYNOPSIS

        my $type = $mime->mime_type('/usr/bin/perl');
        print $type->mime_type;
        print $type->comment;

METHODS

 $type->aliases

    Reference to the aliases of this type

 $type->comment

    Array reference of the type description in various languages (currently
    unused)

 $type->mime_type

        print "Content-Type: " . $type->mime_type . "\r\n";

    String of the content type

 $type->globs

        print $_ for @{ $type->globs };

    Arrayref of the wildcard globs of this type

 $type->priority

        print $type->priority;

    Priority of this type. Types with higher priority get tried first when
    trying to recognize a file type.

    The default priority is 50.

 $type->superclass

        my $sc = $type->superclass;
        print $sc->mime_type;

    The notional superclass of this file type. Note that superclasses don't
    necessarily match the same magic numbers.

 $type->matches $buffer

        my $buf = "PK\003\004"; # first four bytes of file
        if( $type->matches( $buf ) {
            print "Looks like a " . $type->mime_type . " file";
        };

SEE ALSO

    https://www.freedesktop.org/wiki/Software/shared-mime-info/ - the
    website where the XML file is distributed

    File::MimeInfo - module to read your locally installed and converted
    MIME database

    File::LibMagic - if you can install libmagic and the appropriate magic
    files

    File::MMagic - if you have the appropriate magic files

    File::MMagic::XS - if you have the appropriate magic files but want
    more speed

    File::Type - inlines its database, unsupported since 2004?

    File::Type::WebImages - if you're only interested in determining
    whether a file is an image or not

