File-MimeInfo

 view release on metacpan or  search on metacpan

lib/File/MimeInfo/Magic.pm  view on Meta::CPAN


File::MimeInfo::Magic - Determine file type with magic

=head1 SYNOPSIS

    use File::MimeInfo::Magic;
    my $mime_type = mimetype($file);

=head1 DESCRIPTION

This module inherits from L<File::MimeInfo>, it is transparent
to its functions but adds support for the freedesktop magic file.

Magic data is hashed when you need it for the first time.
If you want to force hashing earlier use the C<rehash()> function.

=head1 EXPORT

The method C<mimetype> is exported by default. The methods C<magic>,
C<inodetype>, C<globs> and C<describe> can be exported on demand.

t/05_more.t  view on Meta::CPAN

ok( extensions('text/plain') eq 'asc', 'extenions works');
is_deeply( [extensions('text/plain')], [qw#asc txt#], 'wantarray extensions works' );

# call above should have triggered rehash()
{
    no warnings 'once';
    is(scalar(keys %File::MimeInfo::extension), 7, 'extension data is there');
}

## test alias lookup
ok(mimetype_canon('text/plain') eq 'text/plain', 'canon is transparent');
ok(mimetype_canon('application/x-pdf') eq 'application/pdf', 'canon works');

## test subclass lookup
ok(mimetype_isa('text/foo', 'text/plain'), 'implicite text/plain subclass');
is_deeply([mimetype_isa('text/foo')], [qw(text/plain application/octet-stream)], 'implite application/octet-stream subclass');
ok(mimetype_isa('inode/mount-point', 'inode/directory'), 'implicte inode/directory subclass');
ok(mimetype_isa('application/x-perl', 'application/x-executable'), 'subclass form file');
is_deeply([mimetype_isa('application/x-perl')], [qw(application/x-executable text/plain application/octet-stream)], 'subclass list from file');




( run in 0.371 second using v1.01-cache-2.11-cpan-0a6323c29d9 )