line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
MIME::Type::FileName - guess MIME type using file name extensions |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
in your Perl code: |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use MIME::Type::FileName; |
11
|
|
|
|
|
|
|
my $mimetype = MIME::Type::FileName::guess ("my-file.xls"); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SUMMARY |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
It sounds rather silly, but I can't find a module on CPAN which does something |
17
|
|
|
|
|
|
|
this simple. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Hence I wrote it and released it. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 EXPORTS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
None. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 BUGS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This library is so simple, I guess any bugs would be related to missing mime |
30
|
|
|
|
|
|
|
types. It's probably all very wrong for some reason. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
If you think something is missing, please drop me a mail. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 AUTHOR & LICENSE |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Jean-Michel Hiver - jhiver (at) gmail (dot) com |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module free software and is distributed under the same license as Perl |
40
|
|
|
|
|
|
|
itself. Use it at your own risk. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
package MIME::Type::FileName; |
44
|
1
|
|
|
1
|
|
32249
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
45
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
220
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $VERSION = "1.0"; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our %TYPE = (); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
while () { |
53
|
|
|
|
|
|
|
chomp(); |
54
|
|
|
|
|
|
|
my ($ext, $mime) = split /\s+/, $_; |
55
|
|
|
|
|
|
|
$TYPE{$ext} = $mime; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub guess { |
59
|
5
|
|
|
5
|
0
|
2494
|
my $file = lc(shift); |
60
|
5
|
|
|
|
|
44
|
while ($file =~ s/^.*?\.//) { |
61
|
6
|
100
|
|
|
|
43
|
$TYPE{$file} and return $TYPE{$file}; |
62
|
|
|
|
|
|
|
} |
63
|
2
|
|
|
|
|
8
|
return 'application/octet-stream'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__DATA__ |