| Filename | /usr/lib64/perl5/vendor_perl/5.16.0/File/MimeInfo.pm |
| Statements | Executed 49535 statements in 792ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2564 | 2 | 2 | 418ms | 866ms | File::MimeInfo::globs (recurses: max depth 1, inclusive time 2.30ms) |
| 2560 | 1 | 1 | 152ms | 190ms | File::MimeInfo::inodetype |
| 1 | 1 | 1 | 106ms | 139ms | File::MimeInfo::_hash_globs |
| 5945 | 5 | 1 | 76.8ms | 78.7ms | File::MimeInfo::CORE:match (opcode) |
| 2560 | 1 | 1 | 31.9ms | 31.9ms | File::MimeInfo::CORE:lstat (opcode) |
| 2560 | 1 | 1 | 6.74ms | 6.74ms | File::MimeInfo::CORE:ftfile (opcode) |
| 829 | 2 | 1 | 3.69ms | 3.69ms | File::MimeInfo::CORE:readline (opcode) |
| 1 | 1 | 1 | 1.34ms | 1.36ms | File::MimeInfo::BEGIN@123 |
| 10 | 1 | 1 | 1.32ms | 3.90ms | File::MimeInfo::_glob_to_regexp |
| 90 | 2 | 1 | 978µs | 978µs | File::MimeInfo::CORE:regcomp (opcode) |
| 30 | 3 | 1 | 882µs | 1.64ms | File::MimeInfo::CORE:subst (opcode) |
| 38 | 2 | 1 | 224µs | 224µs | File::MimeInfo::CORE:substcont (opcode) |
| 10 | 1 | 1 | 175µs | 175µs | File::MimeInfo::CORE:qr (opcode) |
| 1 | 1 | 1 | 104µs | 141ms | File::MimeInfo::rehash |
| 1 | 1 | 1 | 85µs | 191µs | File::MimeInfo::BEGIN@3 |
| 1 | 1 | 1 | 80µs | 150µs | File::MimeInfo::BEGIN@121 |
| 1 | 1 | 1 | 78µs | 213µs | File::MimeInfo::BEGIN@5 |
| 1 | 1 | 1 | 59µs | 306µs | File::MimeInfo::BEGIN@4 |
| 1 | 1 | 1 | 51µs | 185µs | File::MimeInfo::BEGIN@7 |
| 1 | 1 | 1 | 48µs | 48µs | File::MimeInfo::CORE:open (opcode) |
| 1 | 1 | 1 | 36µs | 36µs | File::MimeInfo::BEGIN@6 |
| 1 | 1 | 1 | 29µs | 29µs | File::MimeInfo::CORE:close (opcode) |
| 1 | 1 | 1 | 15µs | 15µs | File::MimeInfo::CORE:binmode (opcode) |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::_read_map_files |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::default |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::describe |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::extensions |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::mimetype |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::mimetype_canon |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::mimetype_isa |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::new |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::rehash_aliases |
| 0 | 0 | 0 | 0s | 0s | File::MimeInfo::rehash_subclasses |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package File::MimeInfo; | ||||
| 2 | |||||
| 3 | 2 | 161µs | 2 | 297µs | # spent 191µs (85+106) within File::MimeInfo::BEGIN@3 which was called:
# once (85µs+106µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 3 # spent 191µs making 1 call to File::MimeInfo::BEGIN@3
# spent 106µs making 1 call to strict::import |
| 4 | 2 | 185µs | 2 | 552µs | # spent 306µs (59+246) within File::MimeInfo::BEGIN@4 which was called:
# once (59µs+246µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 4 # spent 306µs making 1 call to File::MimeInfo::BEGIN@4
# spent 246µs making 1 call to Exporter::import |
| 5 | 2 | 154µs | 2 | 348µs | # spent 213µs (78+135) within File::MimeInfo::BEGIN@5 which was called:
# once (78µs+135µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 5 # spent 213µs making 1 call to File::MimeInfo::BEGIN@5
# spent 135µs making 1 call to Exporter::import |
| 6 | 2 | 151µs | 1 | 36µs | # spent 36µs within File::MimeInfo::BEGIN@6 which was called:
# once (36µs+0s) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 6 # spent 36µs making 1 call to File::MimeInfo::BEGIN@6 |
| 7 | 2 | 4.25ms | 2 | 319µs | # spent 185µs (51+134) within File::MimeInfo::BEGIN@7 which was called:
# once (51µs+134µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 7 # spent 185µs making 1 call to File::MimeInfo::BEGIN@7
# spent 134µs making 1 call to Exporter::import |
| 8 | 1 | 4µs | require Exporter; | ||
| 9 | |||||
| 10 | 1 | 41µs | our @ISA = qw(Exporter); | ||
| 11 | 1 | 6µs | our @EXPORT = qw(mimetype); | ||
| 12 | 1 | 9µs | our @EXPORT_OK = qw(extensions describe globs inodetype mimetype_canon mimetype_isa); | ||
| 13 | 1 | 2µs | our $VERSION = '0.15'; | ||
| 14 | 1 | 500ns | our $DEBUG; | ||
| 15 | |||||
| 16 | 1 | 2µs | our ($_hashed, $_hashed_aliases, $_hashed_subclasses); | ||
| 17 | 1 | 2µs | our (@globs, %literal, %extension, %mime2ext, %aliases, %subclasses); | ||
| 18 | 1 | 1µs | our ($LANG, @DIRS); | ||
| 19 | # @globs = [ [ 'glob', qr//, $mime_string ], ... ] | ||||
| 20 | # %literal contains literal matches | ||||
| 21 | # %extension contains extensions (globs matching /^\*(\.\w)+$/ ) | ||||
| 22 | # %mime2ext is used for looking up extension by mime type | ||||
| 23 | # %aliases contains the aliases table | ||||
| 24 | # %subclasses contains the subclasses table | ||||
| 25 | # $LANG can be used to set a default language for the comments | ||||
| 26 | # @DIRS can be used to specify custom database directories | ||||
| 27 | |||||
| 28 | sub new { bless \$VERSION, shift } # what else is there to bless ? | ||||
| 29 | |||||
| 30 | sub mimetype { | ||||
| 31 | my $file = pop; | ||||
| 32 | croak 'subroutine "mimetype" needs a filename as argument' unless defined $file; | ||||
| 33 | croak 'You should use File::MimeInfo::Magic to check open filehandles' if ref $file; | ||||
| 34 | return | ||||
| 35 | inodetype($file) || | ||||
| 36 | globs($file) || | ||||
| 37 | default($file); | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | # spent 190ms (152+38.6) within File::MimeInfo::inodetype which was called 2560 times, avg 74µs/call:
# 2560 times (152ms+38.6ms) by File::MimeInfo::Magic::mimetype at line 39 of File/MimeInfo/Magic.pm, avg 74µs/call | ||||
| 41 | 2560 | 7.82ms | my $file = pop; | ||
| 42 | 2560 | 3.37ms | print STDERR "> Checking inode type\n" if $DEBUG; | ||
| 43 | 2560 | 64.7ms | 2560 | 31.9ms | lstat $file or return undef; # spent 31.9ms making 2560 calls to File::MimeInfo::CORE:lstat, avg 12µs/call |
| 44 | 2560 | 119ms | 2560 | 6.74ms | return undef if -f _; # spent 6.74ms making 2560 calls to File::MimeInfo::CORE:ftfile, avg 3µs/call |
| 45 | my $t = (-l $file) ? 'inode/symlink' : # Win32 does not like '_' here | ||||
| 46 | (-d _) ? 'inode/directory' : | ||||
| 47 | (-p _) ? 'inode/fifo' : | ||||
| 48 | (-c _) ? 'inode/chardevice' : | ||||
| 49 | (-b _) ? 'inode/blockdevice' : | ||||
| 50 | (-S _) ? 'inode/socket' : '' ; | ||||
| 51 | if ($t eq 'inode/directory') { # compare devices to detext mount-points | ||||
| 52 | my $dev = (stat _)[0]; # device of the node under investigation | ||||
| 53 | $file = File::Spec->rel2abs($file); # get full path | ||||
| 54 | my @dirs = File::Spec->splitdir($file); | ||||
| 55 | $file = File::Spec->catfile(@dirs); # removes trailing '/' or equivalent | ||||
| 56 | return $t if -l $file; # parent can be on other dev for links | ||||
| 57 | pop @dirs; | ||||
| 58 | my $dir = File::Spec->catdir(@dirs); # parent dir | ||||
| 59 | $t = 'inode/mount-point' unless (stat $dir)[0] == $dev; # compare devices | ||||
| 60 | return $t; | ||||
| 61 | } | ||||
| 62 | else { return $t ? $t : undef } | ||||
| 63 | } | ||||
| 64 | |||||
| 65 | # spent 866ms (418+448) within File::MimeInfo::globs which was called 2564 times, avg 338µs/call:
# 2560 times (417ms+449ms) by File::MimeInfo::Magic::mimetype at line 44 of File/MimeInfo/Magic.pm, avg 338µs/call
# 4 times (1.48ms+-1.48ms) by File::MimeInfo::globs at line 94, avg 0s/call | ||||
| 66 | 2564 | 19.9ms | my $file = pop; | ||
| 67 | 2564 | 4.28ms | croak 'subroutine "globs" needs a filename as argument' unless defined $file; | ||
| 68 | 2564 | 2.66ms | 1 | 141ms | rehash() unless $_hashed; # spent 141ms making 1 call to File::MimeInfo::rehash |
| 69 | 2564 | 97.0ms | 2564 | 254ms | (undef, undef, $file) = File::Spec->splitpath($file); # remove path # spent 254ms making 2564 calls to File::Spec::Unix::splitpath, avg 99µs/call |
| 70 | 2564 | 3.78ms | print STDERR "> Checking globs for basename '$file'\n" if $DEBUG; | ||
| 71 | |||||
| 72 | 2564 | 14.3ms | return $literal{$file} if exists $literal{$file}; | ||
| 73 | |||||
| 74 | 2564 | 143ms | 2564 | 52.5ms | if ($file =~ /\.(\w+(\.\w+)*)$/) { # spent 52.5ms making 2564 calls to File::MimeInfo::CORE:match, avg 20µs/call |
| 75 | 2564 | 52.2ms | my @ext = split /\./, $1; | ||
| 76 | 2564 | 8.31ms | while (@ext) { | ||
| 77 | 2572 | 18.5ms | my $ext = join('.', @ext); | ||
| 78 | 2572 | 2.82ms | print STDERR "> Checking for extension '.$ext'\n" if $DEBUG; | ||
| 79 | 2572 | 2.74ms | warn "WARNING: wantarray behaviour of globs() will change in the future.\n" if wantarray; | ||
| 80 | return wantarray | ||||
| 81 | 2572 | 74.1ms | ? ($extension{$ext}, $ext) | ||
| 82 | : $extension{$ext} | ||||
| 83 | if exists $extension{$ext}; | ||||
| 84 | 16 | 73µs | shift @ext; | ||
| 85 | } | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | 8 | 193µs | for (@globs) { | ||
| 89 | 80 | 2.73ms | 160 | 919µs | next unless $file =~ $_->[1]; # spent 479µs making 80 calls to File::MimeInfo::CORE:match, avg 6µs/call
# spent 440µs making 80 calls to File::MimeInfo::CORE:regcomp, avg 5µs/call |
| 90 | print STDERR "> This file name matches \"$_->[0]\"\n" if $DEBUG; | ||||
| 91 | return $_->[2]; | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | 8 | 253µs | 12 | 41µs | return globs(lc $file) if $file =~ /[A-Z]/; # recurs # spent 41µs making 8 calls to File::MimeInfo::CORE:match, avg 5µs/call
# spent 2.30ms making 4 calls to File::MimeInfo::globs, avg 574µs/call, recursion: max depth 1, sum of overlapping time 2.30ms |
| 95 | 4 | 67µs | return undef; | ||
| 96 | } | ||||
| 97 | |||||
| 98 | sub default { | ||||
| 99 | my $file = pop; | ||||
| 100 | croak 'subroutine "default" needs a filename as argument' unless defined $file; | ||||
| 101 | |||||
| 102 | my $line; | ||||
| 103 | unless (ref $file) { | ||||
| 104 | return undef unless -f $file; | ||||
| 105 | print STDERR "> File exists, trying default method\n" if $DEBUG; | ||||
| 106 | return 'text/plain' if -z $file; | ||||
| 107 | |||||
| 108 | open FILE, '<', $file || return undef; | ||||
| 109 | binmode FILE, ':utf8' unless $] < 5.008; | ||||
| 110 | read FILE, $line, 32; | ||||
| 111 | close FILE; | ||||
| 112 | } | ||||
| 113 | else { | ||||
| 114 | print STDERR "> Trying default method on object\n" if $DEBUG; | ||||
| 115 | |||||
| 116 | $file->seek(0, SEEK_SET); | ||||
| 117 | $file->read($line, 32); | ||||
| 118 | } | ||||
| 119 | |||||
| 120 | { | ||||
| 121 | 2 | 287µs | 2 | 219µs | # spent 150µs (80+69) within File::MimeInfo::BEGIN@121 which was called:
# once (80µs+69µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 121 # spent 150µs making 1 call to File::MimeInfo::BEGIN@121
# spent 69µs making 1 call to warnings::unimport |
| 122 | if ($] < 5.008 or ! utf8::valid($line)) { | ||||
| 123 | 2 | 8.53ms | 2 | 1.38ms | # spent 1.36ms (1.34+18µs) within File::MimeInfo::BEGIN@123 which was called:
# once (1.34ms+18µs) by RTP::Webmerge::Process::CSS::Inlinedata::BEGIN@32 at line 123 # spent 1.36ms making 1 call to File::MimeInfo::BEGIN@123
# spent 18µs making 1 call to bytes::import |
| 124 | $line =~ s/\s//g; # \m, \n and \t are also control chars | ||||
| 125 | return 'text/plain' unless $line =~ /[\x00-\x1F\x7F]/; | ||||
| 126 | } | ||||
| 127 | else { | ||||
| 128 | # use perl to do something intelligent for ascii & utf8 | ||||
| 129 | return 'text/plain' unless $line =~ /[^[:print:]\s]/; | ||||
| 130 | } | ||||
| 131 | } | ||||
| 132 | print STDERR "> First 10 bytes of the file contain control chars\n" if $DEBUG; | ||||
| 133 | return 'application/octet-stream'; | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | # spent 141ms (104µs+140) within File::MimeInfo::rehash which was called:
# once (104µs+140ms) by File::MimeInfo::globs at line 68 | ||||
| 137 | 1 | 8µs | (@globs, %literal, %extension, %mime2ext) = (); # clear all data | ||
| 138 | 1 | 1µs | local $_; # limit scope of $_ ... :S | ||
| 139 | my @globfiles = @DIRS | ||||
| 140 | 1 | 23µs | 1 | 1.20ms | ? ( grep {-e $_ && -r $_} map "$_/globs", @DIRS ) # spent 1.20ms making 1 call to File::BaseDir::data_files |
| 141 | : ( reverse data_files('mime/globs') ); | ||||
| 142 | 1 | 2µs | print STDERR << 'EOT' unless @globfiles; | ||
| 143 | WARNING: You don't seem to have a mime-info database. The | ||||
| 144 | shared-mime-info package is available from http://freedesktop.org/ . | ||||
| 145 | EOT | ||||
| 146 | 1 | 1µs | my @done; | ||
| 147 | 1 | 5µs | for my $file (@globfiles) { | ||
| 148 | 1 | 2µs | next if grep {$file eq $_} @done; | ||
| 149 | 1 | 12µs | 1 | 139ms | _hash_globs($file); # spent 139ms making 1 call to File::MimeInfo::_hash_globs |
| 150 | 1 | 11µs | push @done, $file; | ||
| 151 | } | ||||
| 152 | 1 | 27µs | $_hashed = 1; | ||
| 153 | } | ||||
| 154 | |||||
| 155 | # spent 139ms (106+33.3) within File::MimeInfo::_hash_globs which was called:
# once (106ms+33.3ms) by File::MimeInfo::rehash at line 149 | ||||
| 156 | 1 | 3µs | my $file = shift; | ||
| 157 | 1 | 78µs | 1 | 48µs | open GLOB, '<', $file || croak "Could not open file '$file' for reading" ; # spent 48µs making 1 call to File::MimeInfo::CORE:open |
| 158 | 1 | 49µs | 1 | 15µs | binmode GLOB, ':utf8' unless $] < 5.008; # spent 15µs making 1 call to File::MimeInfo::CORE:binmode |
| 159 | 1 | 2µs | my ($string, $glob); | ||
| 160 | 1 | 94µs | 3 | 44µs | while (<GLOB>) { # spent 44µs making 3 calls to File::MimeInfo::CORE:readline, avg 15µs/call |
| 161 | 828 | 46.7ms | 1654 | 10.4ms | next if /^\s*#/ or ! /\S/; # skip comments and empty lines # spent 10.4ms making 1654 calls to File::MimeInfo::CORE:match, avg 6µs/call |
| 162 | 826 | 1.92ms | chomp; | ||
| 163 | 826 | 13.3ms | ($string, $glob) = split /:/, $_, 2; | ||
| 164 | 826 | 45.6ms | 2466 | 20.8ms | unless ($glob =~ /[\?\*\[]/) { $literal{$glob} = $string } # spent 15.3ms making 1639 calls to File::MimeInfo::CORE:match, avg 9µs/call
# spent 3.64ms making 826 calls to File::MimeInfo::CORE:readline, avg 4µs/call
# spent 1.85ms making 1 call to utf8::SWASHNEW |
| 165 | elsif ($glob =~ /^\*\.(\w+(\.\w+)*)$/) { | ||||
| 166 | 803 | 12.8ms | $extension{$1} = $string; | ||
| 167 | 803 | 5.66ms | $mime2ext{$string} = [] if !defined($mime2ext{$string}); | ||
| 168 | 803 | 6.91ms | push @{$mime2ext{$string}}, $1; | ||
| 169 | 10 | 243µs | 10 | 3.90ms | } else { unshift @globs, [$glob, _glob_to_regexp($glob), $string] } # spent 3.90ms making 10 calls to File::MimeInfo::_glob_to_regexp, avg 390µs/call |
| 170 | } | ||||
| 171 | 1 | 90µs | 1 | 29µs | close GLOB || croak "Could not open file '$file' for reading" ; # spent 29µs making 1 call to File::MimeInfo::CORE:close |
| 172 | } | ||||
| 173 | |||||
| 174 | # spent 3.90ms (1.32+2.58) within File::MimeInfo::_glob_to_regexp which was called 10 times, avg 390µs/call:
# 10 times (1.32ms+2.58ms) by File::MimeInfo::_hash_globs at line 169, avg 390µs/call | ||||
| 175 | 10 | 34µs | my $glob = shift; | ||
| 176 | 10 | 270µs | 10 | 127µs | $glob =~ s/\./\\./g; # spent 127µs making 10 calls to File::MimeInfo::CORE:subst, avg 13µs/call |
| 177 | 10 | 593µs | 28 | 220µs | $glob =~ s/([?*])/.$1/g; # spent 120µs making 18 calls to File::MimeInfo::CORE:substcont, avg 7µs/call
# spent 100µs making 10 calls to File::MimeInfo::CORE:subst, avg 10µs/call |
| 178 | 10 | 1.12ms | 31 | 2.28ms | $glob =~ s/([^\w\/\\\.\?\*\[\]])/\\$1/g; # spent 1.42ms making 10 calls to File::MimeInfo::CORE:subst, avg 142µs/call
# spent 761µs making 1 call to utf8::SWASHNEW
# spent 105µs making 20 calls to File::MimeInfo::CORE:substcont, avg 5µs/call |
| 179 | 10 | 1.12ms | 20 | 713µs | qr/^$glob$/; # spent 538µs making 10 calls to File::MimeInfo::CORE:regcomp, avg 54µs/call
# spent 175µs making 10 calls to File::MimeInfo::CORE:qr, avg 17µs/call |
| 180 | } | ||||
| 181 | |||||
| 182 | sub extensions { | ||||
| 183 | my $mimet = mimetype_canon(pop @_); | ||||
| 184 | rehash() unless $_hashed; | ||||
| 185 | my $ref = $mime2ext{$mimet} if exists $mime2ext{$mimet}; | ||||
| 186 | return $ref ? @{$ref} : undef if wantarray; | ||||
| 187 | return $ref ? @{$ref}[0] : ''; | ||||
| 188 | } | ||||
| 189 | |||||
| 190 | sub describe { | ||||
| 191 | shift if ref $_[0]; | ||||
| 192 | my ($mt, $lang) = @_; | ||||
| 193 | croak 'subroutine "describe" needs a mimetype as argument' unless $mt; | ||||
| 194 | $mt = mimetype_canon($mt); | ||||
| 195 | $lang = $LANG unless defined $lang; | ||||
| 196 | my $att = $lang ? qq{xml:lang="$lang"} : ''; | ||||
| 197 | my $desc; | ||||
| 198 | my @descfiles = @DIRS | ||||
| 199 | ? ( grep {-e $_ && -r $_} map "$_/$mt.xml", @DIRS ) | ||||
| 200 | : ( reverse data_files('mime', split '/', "$mt.xml") ) ; | ||||
| 201 | for my $file (@descfiles) { | ||||
| 202 | $desc = ''; # if a file was found, return at least empty string | ||||
| 203 | open XML, '<', $file || croak "Could not open file '$file' for reading"; | ||||
| 204 | binmode XML, ':utf8' unless $] < 5.008; | ||||
| 205 | while (<XML>) { | ||||
| 206 | next unless m!<comment\s*$att>(.*?)</comment>!; | ||||
| 207 | $desc = $1; | ||||
| 208 | last; | ||||
| 209 | } | ||||
| 210 | close XML || croak "Could not open file '$file' for reading"; | ||||
| 211 | last if $desc; | ||||
| 212 | } | ||||
| 213 | return $desc; | ||||
| 214 | } | ||||
| 215 | |||||
| 216 | sub mimetype_canon { | ||||
| 217 | my $mimet = pop; | ||||
| 218 | croak 'mimetype_canon needs argument' unless defined $mimet; | ||||
| 219 | rehash_aliases() unless $_hashed_aliases; | ||||
| 220 | return exists($aliases{$mimet}) ? $aliases{$mimet} : $mimet; | ||||
| 221 | } | ||||
| 222 | |||||
| 223 | sub rehash_aliases { | ||||
| 224 | %aliases = _read_map_files('aliases'); | ||||
| 225 | $_hashed_aliases++; | ||||
| 226 | } | ||||
| 227 | |||||
| 228 | sub _read_map_files { | ||||
| 229 | my ($name, $list) = @_; | ||||
| 230 | my @files = @DIRS | ||||
| 231 | ? ( grep {-e $_ && -r $_} map "$_/$name", @DIRS ) | ||||
| 232 | : ( reverse data_files("mime/$name") ); | ||||
| 233 | my (@done, %map); | ||||
| 234 | for my $file (@files) { | ||||
| 235 | next if grep {$_ eq $file} @done; | ||||
| 236 | open MAP, '<', $file || croak "Could not open file '$file' for reading"; | ||||
| 237 | binmode MAP, ':utf8' unless $] < 5.008; | ||||
| 238 | while (<MAP>) { | ||||
| 239 | next if /^\s*#/ or ! /\S/; # skip comments and empty lines | ||||
| 240 | chomp; | ||||
| 241 | my ($k, $v) = split /\s+/, $_, 2; | ||||
| 242 | if ($list) { | ||||
| 243 | $map{$k} = [] unless $map{$k}; | ||||
| 244 | push @{$map{$k}}, $v; | ||||
| 245 | } | ||||
| 246 | else { $map{$k} = $v } | ||||
| 247 | } | ||||
| 248 | close MAP; | ||||
| 249 | push @done, $file; | ||||
| 250 | } | ||||
| 251 | return %map; | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | sub mimetype_isa { | ||||
| 255 | my $parent = pop || croak 'mimetype_isa needs argument'; | ||||
| 256 | my $mimet = pop; | ||||
| 257 | if (ref $mimet or ! defined $mimet) { | ||||
| 258 | $mimet = mimetype_canon($parent); | ||||
| 259 | undef $parent; | ||||
| 260 | } | ||||
| 261 | else { | ||||
| 262 | $mimet = mimetype_canon($mimet); | ||||
| 263 | $parent = mimetype_canon($parent); | ||||
| 264 | } | ||||
| 265 | rehash_subclasses() unless $_hashed_subclasses; | ||||
| 266 | |||||
| 267 | my @subc; | ||||
| 268 | push @subc, 'inode/directory' if $mimet eq 'inode/mount-point'; | ||||
| 269 | push @subc, @{$subclasses{$mimet}} if exists $subclasses{$mimet}; | ||||
| 270 | push @subc, 'text/plain' if $mimet =~ m#^text/#; | ||||
| 271 | push @subc, 'application/octet-stream' unless $mimet =~ m#^inode/#; | ||||
| 272 | |||||
| 273 | return $parent ? scalar(grep {$_ eq $parent} @subc) : @subc; | ||||
| 274 | } | ||||
| 275 | |||||
| 276 | sub rehash_subclasses { | ||||
| 277 | %subclasses = _read_map_files('subclasses', 'LIST'); | ||||
| 278 | $_hashed_subclasses++; | ||||
| 279 | } | ||||
| 280 | |||||
| 281 | 1 | 30µs | 1; | ||
| 282 | |||||
| 283 | __END__ | ||||
# spent 15µs within File::MimeInfo::CORE:binmode which was called:
# once (15µs+0s) by File::MimeInfo::_hash_globs at line 158 | |||||
# spent 29µs within File::MimeInfo::CORE:close which was called:
# once (29µs+0s) by File::MimeInfo::_hash_globs at line 171 | |||||
# spent 6.74ms within File::MimeInfo::CORE:ftfile which was called 2560 times, avg 3µs/call:
# 2560 times (6.74ms+0s) by File::MimeInfo::inodetype at line 44, avg 3µs/call | |||||
# spent 31.9ms within File::MimeInfo::CORE:lstat which was called 2560 times, avg 12µs/call:
# 2560 times (31.9ms+0s) by File::MimeInfo::inodetype at line 43, avg 12µs/call | |||||
# spent 78.7ms (76.8+1.85) within File::MimeInfo::CORE:match which was called 5945 times, avg 13µs/call:
# 2564 times (52.5ms+0s) by File::MimeInfo::globs at line 74, avg 20µs/call
# 1654 times (10.4ms+0s) by File::MimeInfo::_hash_globs at line 161, avg 6µs/call
# 1639 times (13.4ms+1.85ms) by File::MimeInfo::_hash_globs at line 164, avg 9µs/call
# 80 times (479µs+0s) by File::MimeInfo::globs at line 89, avg 6µs/call
# 8 times (41µs+0s) by File::MimeInfo::globs at line 94, avg 5µs/call | |||||
# spent 48µs within File::MimeInfo::CORE:open which was called:
# once (48µs+0s) by File::MimeInfo::_hash_globs at line 157 | |||||
# spent 175µs within File::MimeInfo::CORE:qr which was called 10 times, avg 17µs/call:
# 10 times (175µs+0s) by File::MimeInfo::_glob_to_regexp at line 179, avg 17µs/call | |||||
sub File::MimeInfo::CORE:readline; # opcode | |||||
sub File::MimeInfo::CORE:regcomp; # opcode | |||||
# spent 1.64ms (882µs+761µs) within File::MimeInfo::CORE:subst which was called 30 times, avg 55µs/call:
# 10 times (655µs+761µs) by File::MimeInfo::_glob_to_regexp at line 178, avg 142µs/call
# 10 times (127µs+0s) by File::MimeInfo::_glob_to_regexp at line 176, avg 13µs/call
# 10 times (100µs+0s) by File::MimeInfo::_glob_to_regexp at line 177, avg 10µs/call | |||||
sub File::MimeInfo::CORE:substcont; # opcode |