HTTP::Promise::MIME - MIME Types and File Extension Class
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;
v0.2.0
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.
Provided with an optional file path to a mime.types database and this will return a new instance of HTTP::Promise::MIME
mime.types
If an error occurred, it sets an error and returns undef
undef
print( $m->dump );
This returns a string containing the mime types and their corresponding extensions in a format similar to that of mime.types
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
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
Provided with a mime type and this return the first suffix in scalar context or the list of sufixes found that mime type.
my $ext = $m->suffix( 'application/pgp-signature' ); # $ext is asc my @ext = $m->suffix( 'application/pgp-signature' ); # @ext contains: asc and sig
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
Jacques Deguest <jack@deguest.jp>
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(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.
To install HTTP::Promise, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Promise
CPAN shell
perl -MCPAN -e shell install HTTP::Promise
For more information on module installation, please visit the detailed CPAN module installation guide.