NAME

HTTP::Promise::MIME - MIME Types and File Extension Class

SYNOPSIS

    use HTTP::Promise::MIME;
    my $m = HTTP::Promise::MIME->new || 
        die( HTTP::Promise::MIME->error, "\n" );
    # or you can specify your own mime.types data by providing a file
    my $m = HTTP::Promise::MIME->new( '/etc/mime.types' ) || 
        die( HTTP::Promise::MIME->error, "\n" );
    my $mime = $m->mime_type( '/some/where/file.txt' ); # text/plain
    my $mime = $m->mime_type_from_suffix( 'txt' ); # text/plain
    my $ext = $m->suffix( 'application/pgp-signature' ); # asc
    my @ext = $m->suffix( 'application/pgp-signature' ); # asc, sig
    my $hash = $m->types;

VERSION

    v0.2.0

DESCRIPTION

HTTP::Promise::MIME is a class to find out the mime type of a file or its suffix a.k.a. extension based on its mime type.

The database of mime types is stored internally, so there is no dependence on outside file. You can, however, specify an optional mime database file as the first parameter when instantiating a new object.

CONSTRUCTOR

new

Provided with an optional file path to a mime.types database and this will return a new instance of HTTP::Promise::MIME

If an error occurred, it sets an error and returns undef

METHODS

dump

    print( $m->dump );

This returns a string containing the mime types and their corresponding extensions in a format similar to that of mime.types

mime_type

Provided with a file path, and this returns the mime type of that file.

For example:

    my $mime = $m->mime_type( '/some/where/file.txt' );
    # $mime is text/plain

mime_type_from_suffix

Provided with a suffix, and this will return the equivalent mime type.

Example:

    my $mime = $m->mime_type_from_suffix( 'txt' );
    # $mime is text/plain

suffix

Provided with a mime type and this return the first suffix in scalar context or the list of sufixes found that mime type.

Example:

    my $ext = $m->suffix( 'application/pgp-signature' );
    # $ext is asc
    my @ext = $m->suffix( 'application/pgp-signature' );
    # @ext contains: asc and sig

types

Returns an hash object containing mime types with their corresponding array reference of suffixes.

There is no mime type without suffix.

The internal data is from Apache2 trunk

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mozilla documentation, and other Mozilla documentation

Apache2 trunk

HTTP::Promise, HTTP::Promise::Request, HTTP::Promise::Response, HTTP::Promise::Message, HTTP::Promise::Entity, HTTP::Promise::Headers, HTTP::Promise::Body, HTTP::Promise::Body::Form, HTTP::Promise::Body::Form::Data, HTTP::Promise::Body::Form::Field, HTTP::Promise::Status, HTTP::Promise::MIME, HTTP::Promise::Parser, HTTP::Promise::IO, HTTP::Promise::Stream, HTTP::Promise::Exception

COPYRIGHT & LICENSE

Copyright(c) 2022 DEGUEST Pte. Ltd.

All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.