Acme-CPANModules-MIMETypes
view release on metacpan or search on metacpan
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
{
"abstract" : "List of modules to work with MIME types",
"author" : [
"perlancar <perlancar@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.028, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "0.001"
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Acme-CPANModules-MIMETypes"
},
"homepage" : "https://metacpan.org/release/Acme-CPANModules-MIMETypes",
"repository" : {
"type" : "git",
"url" : "git://github.com/perlancar/perl-Acme-CPANModules-MIMETypes.git",
"web" : "https://github.com/perlancar/perl-Acme-CPANModules-MIMETypes"
}
},
"version" : "0.001",
"x_Dist_Zilla" : {
"perl" : {
"version" : "5.034000"
},
"plugins" : [
{
"class" : "Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple",
"name" : "@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple",
"version" : "0.04"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "runtime",
"type" : "requires"
}
},
"name" : "Prereqs",
"version" : "6.028"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "develop",
"type" : "x_spec"
}
},
"name" : "DevelopX_spec",
"version" : "6.028"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":InstallModules",
"version" : "6.028"
},
---
abstract: 'List of modules to work with MIME types'
author:
- 'perlancar <perlancar@cpan.org>'
build_requires:
File::Spec: '0'
IO::Handle: '0'
IPC::Open3: '0'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
version: '0.006'
-
class: Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple
name: '@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple'
version: '0.04'
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: runtime
type: requires
name: Prereqs
version: '6.028'
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: develop
type: x_spec
name: DevelopX_spec
version: '6.028'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':InstallModules'
version: '6.028'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':IncModules'
version: '6.028'
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.028.
use strict;
use warnings;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "List of modules to work with MIME types",
"AUTHOR" => "perlancar <perlancar\@cpan.org>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Acme-CPANModules-MIMETypes",
"LICENSE" => "perl",
"NAME" => "Acme::CPANModules::MIMETypes",
"PREREQ_PM" => {
"Acme::CPANModulesUtil::Misc" => 0,
"strict" => 0,
NAME
Acme::CPANModules::MIMETypes - List of modules to work with MIME types
VERSION
This document describes version 0.001 of Acme::CPANModules::MIMETypes
(from Perl distribution Acme-CPANModules-MIMETypes), released on
2023-06-30.
DESCRIPTION
All recipes are categorized by tasks, then by most recommended module.
1. Finding out filename extensions for a certain MIME type
1a. With File::MimeInfo (uses system's type database):
use File::MimeInfo qw(extensions);
$ext = extensions("image/jpeg"); # => "jpeg"
@exts = extensions("image/jpeg"); # => ("jpeg", "jpe", "jpg")
1b. With MIME::Types (comes with its own type database):
use MIME::Types;
my $mt = MIME::Types->new->type("image/jpeg") or die "Unknown MIME type";
my @exts = $m->extensions; # => ("jpeg", "jpg", "jpe", "jfif", "jfif-tbnl")
1c. With Media::Type::Simple (can uses system's "/etc/mime.types"):
use Media::Type::Simple;
$ext = ext_from_type("image/jpeg"); # => "jpeg"
@exts = ext_from_type("image/jpeg"); # => ("jpeg", "jpg", "jpe", "jfif")
2. Finding out the MIME type associated with a certain filename
extension
2a. With MIME::Types:
use MIME::Types;
my $mt = MIME::Types->new->mimeTypeOf("gif") or die "Unknown MIME type";
say "$mt" ;# => "image/gif"
2b. With Media::Type::Simple:
use Media::Type::Simple;
$type = type_from_ext("jpg"); # => "image/jpeg"
2c. With MIME::Type::FileName (comes with its own type database, last
updated 2012):
use MIME::Type::FileName;
my $mimetype = MIME::Type::FileName::guess ("my-file.xls") or die "Unknown MIME type";
3. Guessing MIME type of a file based on its extension
3a. With File::MimeInfo:
use File::MimeInfo;
my $mime_type = mimetype('test.png') or die "Unknown MIME type";
3b. With LWP::MediaTypes (comes with its own type database):
use LWP::MediaTypes;
my $type = LWP::MediaTypes::guess_media_type("file.xls") or die "Unknown MIME type";
4. Guessing MIME type of a file based on its content
4a. Using File::MimeInfo::Magic (same interface as File::MimeInfo):
use File::MimeInfo::Magic;
$type = mimetype("file.jpg"); # => "image/jpeg"
# For symlink, will return "octet/symlink". To follow symlink, open file and
# pass filehandle.
open my $fh, "<", "symlink-to-file.jpg" or die "Can't open file: $!";
$type = mimetype($fh); # => "image/jpeg"
4b. Using other modules:
Alien::LibMagic
File::LibMagic
File::LibMagic::FFI
File::MMagic
lib/Acme/CPANModules/MIMETypes.pm view on Meta::CPAN
use Acme::CPANModulesUtil::Misc;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-06-30'; # DATE
our $DIST = 'Acme-CPANModules-MIMETypes'; # DIST
our $VERSION = '0.001'; # VERSION
my $text = <<'_';
All recipes are categorized by tasks, then by most recommended module.
**1. Finding out filename extensions for a certain MIME type**
**1a. With <pm:File::MimeInfo> (uses system's type database):**
use File::MimeInfo qw(extensions);
$ext = extensions("image/jpeg"); # => "jpeg"
@exts = extensions("image/jpeg"); # => ("jpeg", "jpe", "jpg")
**1b. With <pm:MIME::Types> (comes with its own type database):**
use MIME::Types;
my $mt = MIME::Types->new->type("image/jpeg") or die "Unknown MIME type";
my @exts = $m->extensions; # => ("jpeg", "jpg", "jpe", "jfif", "jfif-tbnl")
**1c. With <pm:Media::Type::Simple> (can uses system's C</etc/mime.types>):**
use Media::Type::Simple;
$ext = ext_from_type("image/jpeg"); # => "jpeg"
@exts = ext_from_type("image/jpeg"); # => ("jpeg", "jpg", "jpe", "jfif")
**2. Finding out the MIME type associated with a certain filename extension**
**2a. With MIME::Types:**
use MIME::Types;
my $mt = MIME::Types->new->mimeTypeOf("gif") or die "Unknown MIME type";
say "$mt" ;# => "image/gif"
**2b. With Media::Type::Simple:**
use Media::Type::Simple;
$type = type_from_ext("jpg"); # => "image/jpeg"
**2c. With <pm:MIME::Type::FileName> (comes with its own type database, last updated 2012):**
use MIME::Type::FileName;
my $mimetype = MIME::Type::FileName::guess ("my-file.xls") or die "Unknown MIME type";
**3. Guessing MIME type of a file based on its extension**
**3a. With File::MimeInfo:**
use File::MimeInfo;
my $mime_type = mimetype('test.png') or die "Unknown MIME type";
**3b. With <pm:LWP::MediaTypes> (comes with its own type database):**
use LWP::MediaTypes;
my $type = LWP::MediaTypes::guess_media_type("file.xls") or die "Unknown MIME type";
**4. Guessing MIME type of a file based on its content**
**4a. Using <pm:File::MimeInfo::Magic> (same interface as File::MimeInfo):**
use File::MimeInfo::Magic;
$type = mimetype("file.jpg"); # => "image/jpeg"
# For symlink, will return "octet/symlink". To follow symlink, open file and
# pass filehandle.
open my $fh, "<", "symlink-to-file.jpg" or die "Can't open file: $!";
$type = mimetype($fh); # => "image/jpeg"
**4b. Using other modules:**
<pm:Alien::LibMagic>
<pm:File::LibMagic>
<pm:File::LibMagic::FFI>
<pm:File::MMagic>
<pm:File::MMagic::XS>
<pm:File::Type>
_
our $LIST = {
summary => 'List of modules to work with MIME types',
tags => ['recipes'],
description => $text,
};
Acme::CPANModulesUtil::Misc::populate_entries_from_module_links_in_description;
1;
# ABSTRACT: List of modules to work with MIME types
__END__
=pod
=encoding UTF-8
=head1 NAME
Acme::CPANModules::MIMETypes - List of modules to work with MIME types
=head1 VERSION
This document describes version 0.001 of Acme::CPANModules::MIMETypes (from Perl distribution Acme-CPANModules-MIMETypes), released on 2023-06-30.
=head1 DESCRIPTION
All recipes are categorized by tasks, then by most recommended module.
B<1. Finding out filename extensions for a certain MIME type>
B<< 1a. With L<File::MimeInfo> (uses system's type database): >>
use File::MimeInfo qw(extensions);
$ext = extensions("image/jpeg"); # => "jpeg"
@exts = extensions("image/jpeg"); # => ("jpeg", "jpe", "jpg")
B<< 1b. With L<MIME::Types> (comes with its own type database): >>
use MIME::Types;
my $mt = MIME::Types->new->type("image/jpeg") or die "Unknown MIME type";
my @exts = $m->extensions; # => ("jpeg", "jpg", "jpe", "jfif", "jfif-tbnl")
B<< 1c. With L<Media::Type::Simple> (can uses system's C</etc/mime.types>): >>
use Media::Type::Simple;
$ext = ext_from_type("image/jpeg"); # => "jpeg"
@exts = ext_from_type("image/jpeg"); # => ("jpeg", "jpg", "jpe", "jfif")
B<2. Finding out the MIME type associated with a certain filename extension>
B<2a. With MIME::Types:>
use MIME::Types;
my $mt = MIME::Types->new->mimeTypeOf("gif") or die "Unknown MIME type";
say "$mt" ;# => "image/gif"
B<2b. With Media::Type::Simple:>
use Media::Type::Simple;
$type = type_from_ext("jpg"); # => "image/jpeg"
B<< 2c. With L<MIME::Type::FileName> (comes with its own type database, last updated 2012): >>
use MIME::Type::FileName;
my $mimetype = MIME::Type::FileName::guess ("my-file.xls") or die "Unknown MIME type";
B<3. Guessing MIME type of a file based on its extension>
B<3a. With File::MimeInfo:>
use File::MimeInfo;
my $mime_type = mimetype('test.png') or die "Unknown MIME type";
B<< 3b. With L<LWP::MediaTypes> (comes with its own type database): >>
use LWP::MediaTypes;
my $type = LWP::MediaTypes::guess_media_type("file.xls") or die "Unknown MIME type";
B<4. Guessing MIME type of a file based on its content>
B<< 4a. Using L<File::MimeInfo::Magic> (same interface as File::MimeInfo): >>
use File::MimeInfo::Magic;
$type = mimetype("file.jpg"); # => "image/jpeg"
# For symlink, will return "octet/symlink". To follow symlink, open file and
# pass filehandle.
open my $fh, "<", "symlink-to-file.jpg" or die "Can't open file: $!";
$type = mimetype($fh); # => "image/jpeg"
B<4b. Using other modules:>
L<Alien::LibMagic>
L<File::LibMagic>
L<File::LibMagic::FFI>
L<File::MMagic>
( run in 0.555 second using v1.01-cache-2.11-cpan-df04353d9ac )