MimeInfo.pm

filter: Statementstmt 94.7% 200 / 211 Branchbran 65.7% 121 / 184 Conditioncond 59.2% 16 / 27 MC/DCmcdc 35.2% 6 / 17 Subroutinesub 100% 24 / 24 Podpod 100% 13 / 13 totaltotal 79.8% 380 / 476 CC 106 SCAR 28.0
CC
106
Cov
80%
default
44.7
inodetype
19.8
describe
18.7
CRAP 16.5
« MimeInfo/Magic.pm ↑ Summary
1 package File::MimeInfo;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Fcntl 'SEEK_SET';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use File::BaseDir qw/data_files/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 require Exporter;
10  
11 9 our @ISA = qw(Exporter);
12 9 our @EXPORT = qw(mimetype);
13 9 our @EXPORT_OK = qw(extensions describe globs inodetype mimetype_canon mimetype_isa);
14 9 our $VERSION = '0.33';
15 9 our $DEBUG;
16  
17 9 our ($_hashed, $_hashed_aliases, $_hashed_subclasses, $_has_mimeinfo_database);
18 9 our (@globs, %literal, %extension, %mime2ext, %aliases, %subclasses);
19 9 our ($LANG, @DIRS);
20 # @globs = [ [ 'glob', qr//, $mime_string ], ... ]
21 # %literal contains literal matches
22 # %extension contains extensions (globs matching /^\*(\.\w)+$/ )
23 # %mime2ext is used for looking up extension by mime type
24 # %aliases contains the aliases table
25 # %subclasses contains the subclasses table
26 # $LANG can be used to set a default language for the comments
27 # @DIRS can be used to specify custom database directories
28  
29 1 ▶sub new { bless \$VERSION, shift } # what else is there to bless ?
Subroutine new: called CC=1 SCAR=0.0
Pod documented
30  
31 sub mimetype {
32 21 ▶ my $file = pop;
Subroutine mimetype: called CC=4 SCAR=13.9
Pod documented
33 21 ▶ croak 'subroutine "mimetype" needs a filename as argument' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 21 21
34 return
35 21 ▶ inodetype($file) ||
Condition100%6/6
inodetype($file) || globs($file) || default($file)
l!l&&r!l&&!r
1551
inodetype($file) or globs($file)
l!l&&r!l&&!r
2136
MC/DC100%3/3
inodetype($file) || globs($file) || default($file)
inodetype($file) globs($file) default($file)
Truth table100%4/4
A or B || C
A= inodetype($file)B= globs($file)C= default($file)
ABCresult
1XX1
01X1
0011
0000
36 globs($file) ||
37 default($file);
38 }
39  
40 sub inodetype {
41 29 ▶ my $file = pop;
Subroutine inodetype: called CC=14 SCAR=29.9
Pod documented
42 29 ▶ print STDERR "> Checking inode type\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 29 29
43 29 ▶ lstat $file or return undef;
Branch: 1 branch
BranchTrueFalseTotal
lstat $file or return undef 13 16 29
44 16 ▶ return undef if -f _;
Branch: 1 branch
BranchTrueFalseTotal
if -f _ 14 2 16
45 2 ▶ my $t = (-l $file) ? 'inode/symlink' : # Win32 does not like '_' here
Branch: 6 branches
BranchTrueFalseTotal
-l $file ? : 1 1 2
-d _ ? : 1 0 1
-p _ ? : 0 0 0
-c _ ? : 0 0 0
-b _ ? : 0 0 0
-S _ ? : 0 0 0
46 (-d _) ? 'inode/directory' :
47 (-p _) ? 'inode/fifo' :
48 (-c _) ? 'inode/chardevice' :
49 (-b _) ? 'inode/blockdevice' :
50 (-S _) ? 'inode/socket' : '' ;
51 2 ▶ if ($t eq 'inode/directory') { # compare devices to detect mount-points
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq 'inode/directory') { } 1 1 2
52 1 my $dev = (stat _)[0]; # device of the node under investigation
53 1 $file = File::Spec->rel2abs($file); # get full path
54 1 my @dirs = File::Spec->splitdir($file);
55 1 $file = File::Spec->catfile(@dirs); # removes trailing '/' or equivalent
56 1 ▶ return $t if -l $file; # parent can be on other dev for links
Branch: 1 branch
BranchTrueFalseTotal
if -l $file 0 1 1
57 1 pop @dirs;
58 1 my $dir = File::Spec->catdir(@dirs); # parent dir
59 1 ▶ $t = 'inode/mount-point' unless (stat $dir)[0] == $dev; # compare devices
Branch: 1 branch
BranchTrueFalseTotal
unless (stat $dir)[0] == $dev 0 1 1
60 1 return $t;
61 }
62 1 ▶ else { return $t ? $t : undef }
Branch: 1 branch
BranchTrueFalseTotal
$t ? : 1 0 1
63 }
64  
65 sub globs {
66 25 ▶ my $file = pop;
Subroutine globs: called CC=15 SCAR=27.4
Pod documented
67 25 ▶ croak 'subroutine "globs" needs a filename as argument' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 25 25
68 25 ▶ rehash() unless $_hashed;
Branch: 1 branch
BranchTrueFalseTotal
unless $File::MimeInfo::_hashed 1 24 25
69 25 (undef, undef, $file) = File::Spec->splitpath($file); # remove path
70 25 ▶ print STDERR "> Checking globs for basename '$file'\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 25 25
71  
72 25 ▶ return $literal{$file} if exists $literal{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $File::MimeInfo::literal{$file} 1 24 25
73  
74 24 ▶ if ($file =~ /\.(\w+(\.\w+)*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.(\w+(\.\w+)*)$/) 11 13 24
75 11 my @ext = split /\./, $1;
76 11 ▶ while (@ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ext) 16 1 17
77 16 my $ext = join('.', @ext);
78 16 ▶ print STDERR "> Checking for extension '.$ext'\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 16 16
79 16 ▶ carp "WARNING: wantarray behaviour of globs() will change in the future.\n" if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 16 16
80 return wantarray
81 ? ($extension{$ext}, $ext)
82 : $extension{$ext}
83 16 ▶ if exists $extension{$ext};
Branch: 2 branches
BranchTrueFalseTotal
if exists $File::MimeInfo::extension{$ext} 10 6 16
wantarray ? : 0 10 10
84 6 shift @ext;
85 }
86 }
87  
88 14 for (@globs) {
89 14 ▶ next unless $file =~ $_->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /$_->[1]/ 12 2 14
90 2 ▶ print STDERR "> This file name matches \"$_->[0]\"\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 2 2
91 2 return $_->[2];
92 }
93  
94 12 ▶ return globs(lc $file) if $file =~ /[A-Z]/; # recurs
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /[A-Z]/ 1 11 12
95 11 return undef;
96 }
97  
98 sub default {
99 8 ▶ my $file = pop;
Subroutine default: called CC=19 SCAR=38.0
Pod documented
100 8 ▶ croak 'subroutine "default" needs a filename as argument' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 8 8
101  
102 8 my $line;
103 8 ▶ unless (ref $file) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $file) { } 0 8 8
if (do { ref $file eq 'Path::Tiny' }) { } 0 0 0
104 8 ▶ return undef unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 1 7 8
105 7 ▶ print STDERR "> File exists, trying default method\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 7 7
106 7 ▶ return 'text/plain' if -z $file;
Branch: 1 branch
BranchTrueFalseTotal
if -z $file 1 6 7
107  
108 6 ▶ open FILE, '<', $file or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", $file or return undef 0 6 6
109 6 ▶ binmode FILE, ':utf8' unless $] < 5.008;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.008" 6 0 6
110 6 read FILE, $line, 32;
111 6 close FILE;
112 }
113 elsif (ref $file eq 'Path::Tiny') {
114 0 ▶ return undef unless $file->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->exists 0 0 0
115 0 ▶ print STDERR "> File is Path::Tiny object and exists, "
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 0 0
116 . "trying default method\n" if $DEBUG;
117 0 ▶ open my $fh, '<', $file or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return undef 0 0 0
118 0 ▶ binmode FILE, ':utf8' unless $] < 5.008;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.008" 0 0 0
119 0 read $fh, $line, 32;
120 0 close $fh;
121 }
122 else {
123 0 ▶ print STDERR "> Trying default method on object\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 0 0
124  
125 0 $file->seek(0, SEEK_SET);
126 0 $file->read($line, 32);
127 }
128  
129 {
130 9 ▶ no warnings; # warnings can be thrown when input not ascii
Subroutine BEGIN: called CC=1 SCAR=0.0
131 6 ▶ if ($] < 5.008 or ! utf8::valid($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.008 or not utf8::valid($line)) { } 2 4 6
Condition66%2/3
$] < "5.008" or not utf8::valid($line)
l!l&&r!l&&!r
024
MC/DC50%1/2
$] < "5.008" or not utf8::valid($line)
$] < "5.008" not utf8::valid($line)
Truth table66%2/3
A or not(B)
A= $] < "5.008"B= not utf8::valid($line)
ABresult
1X1
011
000
132 9 ▶ use bytes; # avoid invalid utf8 chars
Subroutine BEGIN: called CC=1 SCAR=0.0
133 2 $line =~ s/\s//g; # \m, \n and \t are also control chars
134 2 ▶ return 'text/plain' unless $line =~ /[\x00-\x1F\x7F]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /[\x00-\x1F\x7F]/ 0 2 2
135 }
136 else {
137 # use perl to do something intelligent for ascii & utf8
138 4 ▶ return 'text/plain' unless $line =~ /[^[:print:]\s]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /[^[:print:]\s]/ 3 1 4
139 }
140 }
141 3 ▶ print STDERR "> First 10 bytes of the file contain control chars\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::DEBUG 0 3 3
142 3 return 'application/octet-stream';
143 }
144  
145 sub rehash {
146 5 ▶ (@globs, %literal, %extension, %mime2ext) = (); # clear all data
Subroutine rehash: called CC=6 SCAR=17.9
Pod documented
147 5 local $_; # limit scope of $_ ... :S
148 my @globfiles = @DIRS
149 5 ▶ ? ( grep {-e $_ && -r $_} map "$_/globs", @DIRS )
Branch: 2 branches
BranchTrueFalseTotal
@File::MimeInfo::DIRS ? : 1 4 5
-e $_ and -r $_ 1 0 1
150 : ( reverse data_files('mime/globs') );
151 5 ▶ if (@globfiles) {
Branch: 1 branch
BranchTrueFalseTotal
if (@globfiles) { } 3 2 5
152 3 $_has_mimeinfo_database = 1;
153 } else {
154 2 carp "WARNING: You don't seem to have a mime-info database. " .
155 "The shared-mime-info package is available from http://freedesktop.org/";
156 }
157 5 my @done;
158 5 for my $file (@globfiles) {
159 5 ▶ next if grep {$file eq $_} @done;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$file eq $_;} @done 2 3 5
160 3 _hash_globs($file);
161 3 push @done, $file;
162 }
163 5 $_hashed = 1;
164 }
165  
166 sub _hash_globs {
167 3 ▶ my $file = shift;
Subroutine _hash_globs: called CC=11 SCAR=24.2
168 3 ▶ open GLOB, '<', $file || croak "Could not open file '$file' for reading" ;
Condition33%1/3
$file || croak("Could not open file '${file}' for reading")
l!l&&r!l&&!r
300
MC/DC0%0/2
$file || croak("Could not open file '${file}' for reading")
$file croak("Could not open file '${file}' for reading")
Truth table33%1/3
A || B
A= $fileB= croak("Could not open file '${file}' for reading")
ABresult
1X1
011
000
169 3 ▶ binmode GLOB, ':utf8' unless $] < 5.008;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.008" 3 0 3
170 3 my ($string, $glob);
171 3 ▶ while (<GLOB>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline GLOB)) 33 3 36
172 33 ▶ next if /^\s*#/ or ! /\S/; # skip comments and empty lines
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/ or not /\S/ 3 30 33
Condition66%2/3
/^\s*#/ or not /\S/
l!l&&r!l&&!r
3030
MC/DC50%1/2
/^\s*#/ or not /\S/
/^\s*#/ not /\S/
Truth table66%2/3
A or not(B)
A= /^\s*#/B= not /\S/
ABresult
1X1
011
000
173 30 chomp;
174 30 ($string, $glob) = split /:/, $_, 2;
175 30 ▶ unless ($glob =~ /[\?\*\[]/) { $literal{$glob} = $string }
Branch: 2 branches
BranchTrueFalseTotal
if ($glob =~ /[\?\*\[]/) { } 27 3 30
if (do { $glob =~ /^\*\.(\w+(\.\w+)*)$/ }) { } 24 3 27
176 elsif ($glob =~ /^\*\.(\w+(\.\w+)*)$/) {
177 24 ▶ $extension{$1} = $string unless exists $extension{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $File::MimeInfo::extension{$1} 21 3 24
178 24 ▶ $mime2ext{$string} = [] if !defined($mime2ext{$string});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::MimeInfo::mime2ext{$string} 21 3 24
179 24 push @{$mime2ext{$string}}, $1;
180 3 } else { unshift @globs, [$glob, _glob_to_regexp($glob), $string] }
181 }
182 3 ▶ close GLOB || croak "Could not open file '$file' for reading" ;
Branch: 1 branch
BranchTrueFalseTotal
close GLOB or croak("Could not open file '${file}' for reading") 0 3 3
183 }
184  
185 sub _glob_to_regexp {
186 7 ▶ my $glob = shift;
Subroutine _glob_to_regexp: called CC=1 SCAR=0.0
187 7 $glob =~ s/\./\\./g;
188 7 $glob =~ s/([?*])/.$1/g;
189 7 $glob =~ s/([^\w\/\\\.\?\*\[\]])/\\$1/g;
190 7 qr/^$glob$/;
191 }
192  
193 sub has_mimeinfo_database {
194 2 ▶ rehash() if (!$_hashed);
Subroutine has_mimeinfo_database: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $File::MimeInfo::_hashed 2 0 2
195 2 return $_has_mimeinfo_database;
196 }
197  
198 sub extensions {
199 2 ▶ my $mimet = mimetype_canon(pop @_);
Subroutine extensions: called CC=6 SCAR=18.2
Pod documented
200 2 ▶ rehash() unless $_hashed;
Branch: 1 branch
BranchTrueFalseTotal
unless $File::MimeInfo::_hashed 1 1 2
201 2 ▶ my $ref = $mime2ext{$mimet} if exists $mime2ext{$mimet};
Branch: 1 branch
BranchTrueFalseTotal
if exists $File::MimeInfo::mime2ext{$mimet} 2 0 2
202 2 ▶ return $ref ? @{$ref} : undef if wantarray;
Branch: 2 branches
BranchTrueFalseTotal
if wantarray 1 1 2
$ref ? : 1 0 1
203 1 ▶ return $ref ? @{$ref}[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
$ref ? : 1 0 1
204 }
205  
206 sub describe {
207 2 ▶ shift if ref $_[0];
Subroutine describe: called CC=14 SCAR=29.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 2 2
208 2 my ($mt, $lang) = @_;
209 2 ▶ croak 'subroutine "describe" needs a mimetype as argument' unless $mt;
Branch: 1 branch
BranchTrueFalseTotal
unless $mt 0 2 2
210 2 $mt = mimetype_canon($mt);
211 2 ▶ $lang = $LANG unless defined $lang;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lang 2 0 2
212 2 ▶ my $att = $lang ? qq{xml:lang="$lang"} : '';
Branch: 1 branch
BranchTrueFalseTotal
$lang ? : 1 1 2
213 2 my $desc;
214 my @descfiles = @DIRS
215 2 ▶ ? ( grep {-e $_ && -r $_} map "$_/$mt.xml", @DIRS )
Branch: 2 branches
BranchTrueFalseTotal
@File::MimeInfo::DIRS ? : 0 2 2
-e $_ and -r $_ 0 0 0
216 : ( reverse data_files('mime', split '/', "$mt.xml") ) ;
217 2 for my $file (@descfiles) {
218 2 $desc = ''; # if a file was found, return at least empty string
219 2 ▶ open XML, '<', $file || croak "Could not open file '$file' for reading";
Condition33%1/3
$file || croak("Could not open file '${file}' for reading")
l!l&&r!l&&!r
200
MC/DC0%0/2
$file || croak("Could not open file '${file}' for reading")
$file croak("Could not open file '${file}' for reading")
Truth table33%1/3
A || B
A= $fileB= croak("Could not open file '${file}' for reading")
ABresult
1X1
011
000
220 2 ▶ binmode XML, ':utf8' unless $] < 5.008;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.008" 2 0 2
221 2 ▶ while (<XML>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline XML)) 20 0 20
222 20 ▶ next unless m!<comment\s*$att>(.*?)</comment>!;
Branch: 1 branch
BranchTrueFalseTotal
unless m[<comment\s*$att>(.*?)</comment>] 18 2 20
223 2 $desc = $1;
224 2 last;
225 }
226 2 ▶ close XML || croak "Could not open file '$file' for reading";
Branch: 1 branch
BranchTrueFalseTotal
close XML or croak("Could not open file '${file}' for reading") 0 2 2
227 2 ▶ last if $desc;
Branch: 1 branch
BranchTrueFalseTotal
if $desc 2 0 2
228 }
229 2 return $desc;
230 }
231  
232 sub mimetype_canon {
233 16 ▶ my $mimet = pop;
Subroutine mimetype_canon: called CC=4 SCAR=13.9
Pod documented
234 16 ▶ croak 'mimetype_canon needs argument' unless defined $mimet;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mimet 0 16 16
235 16 ▶ rehash_aliases() unless $_hashed_aliases;
Branch: 1 branch
BranchTrueFalseTotal
unless $File::MimeInfo::_hashed_aliases 2 14 16
236 16 ▶ return exists($aliases{$mimet}) ? $aliases{$mimet} : $mimet;
Branch: 1 branch
BranchTrueFalseTotal
exists $File::MimeInfo::aliases{$mimet} ? : 1 15 16
237 }
238  
239 sub rehash_aliases {
240 2 ▶ %aliases = _read_map_files('aliases');
Subroutine rehash_aliases: called CC=1 SCAR=0.0
Pod documented
241 2 $_hashed_aliases++;
242 }
243  
244 sub _read_map_files {
245 3 ▶ my ($name, $list) = @_;
Subroutine _read_map_files: called CC=12 SCAR=25.9
246 my @files = @DIRS
247 3 ▶ ? ( grep {-e $_ && -r $_} map "$_/$name", @DIRS )
Branch: 2 branches
BranchTrueFalseTotal
@File::MimeInfo::DIRS ? : 0 3 3
-e $_ and -r $_ 0 0 0
248 : ( reverse data_files("mime/$name") );
249 3 my (@done, %map);
250 3 for my $file (@files) {
251 6 ▶ next if grep {$_ eq $file} @done;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $file;} @done 3 3 6
252 3 ▶ open MAP, '<', $file || croak "Could not open file '$file' for reading";
Condition33%1/3
$file || croak("Could not open file '${file}' for reading")
l!l&&r!l&&!r
300
MC/DC0%0/2
$file || croak("Could not open file '${file}' for reading")
$file croak("Could not open file '${file}' for reading")
Truth table33%1/3
A || B
A= $fileB= croak("Could not open file '${file}' for reading")
ABresult
1X1
011
000
253 3 ▶ binmode MAP, ':utf8' unless $] < 5.008;
Branch: 1 branch
BranchTrueFalseTotal
unless $] < "5.008" 3 0 3
254 3 ▶ while (my $line = <MAP>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline MAP)) 6 3 9
255 6 ▶ next unless $line =~ m/\S/; # skip empty lines
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 6 6
256 6 ▶ next if $line =~ m/^\s*#/; # skip comment lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 0 6 6
257 6 chomp $line;
258 6 my ($k, $v) = split m/\s+/, $line, 2;
259 6 ▶ if ($list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list) { } 2 4 6
260 2 ▶ $map{$k} = [] unless $map{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $map{$k} 1 1 2
261 2 push @{$map{$k}}, $v;
262 }
263 4 else { $map{$k} = $v }
264 }
265 3 close MAP;
266 3 push @done, $file;
267 }
268 3 return %map;
269 }
270  
271 sub mimetype_isa {
272 5 ▶ my $parent = pop || croak 'mimetype_isa needs argument';
Subroutine mimetype_isa: called CC=10 SCAR=23.1
Pod documented
Condition33%1/3
pop() || croak('mimetype_isa needs argument')
l!l&&r!l&&!r
500
MC/DC0%0/2
pop() || croak('mimetype_isa needs argument')
pop() croak('mimetype_isa needs argument')
Truth table33%1/3
A || B
A= pop()B= croak('mimetype_isa needs argument')
ABresult
1X1
011
000
273 5 my $mimet = pop;
274 5 ▶ if (ref $mimet or ! defined $mimet) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mimet or not defined $mimet) { } 2 3 5
Condition66%2/3
ref $mimet or not defined $mimet
l!l&&r!l&&!r
023
MC/DC50%1/2
ref $mimet or not defined $mimet
ref $mimet not defined $mimet
Truth table66%2/3
A or not(B)
A= ref $mimetB= not defined $mimet
ABresult
1X1
011
000
275 2 $mimet = mimetype_canon($parent);
276 2 undef $parent;
277 }
278 else {
279 3 $mimet = mimetype_canon($mimet);
280 3 $parent = mimetype_canon($parent);
281 }
282 5 ▶ rehash_subclasses() unless $_hashed_subclasses;
Branch: 1 branch
BranchTrueFalseTotal
unless $File::MimeInfo::_hashed_subclasses 1 4 5
283  
284 5 my @subc;
285 5 ▶ push @subc, 'inode/directory' if $mimet eq 'inode/mount-point';
Branch: 1 branch
BranchTrueFalseTotal
if $mimet eq "inode/mount-point" 1 4 5
286 5 ▶ push @subc, @{$subclasses{$mimet}} if exists $subclasses{$mimet};
Branch: 1 branch
BranchTrueFalseTotal
if exists $File::MimeInfo::subclasses{$mimet} 2 3 5
287 5 ▶ push @subc, 'text/plain' if $mimet =~ m#^text/#;
Branch: 1 branch
BranchTrueFalseTotal
if $mimet =~ m[^text/] 2 3 5
288 5 ▶ push @subc, 'application/octet-stream' unless $mimet =~ m#^inode/#;
Branch: 1 branch
BranchTrueFalseTotal
unless $mimet =~ m[^inode/] 4 1 5
289  
290 5 ▶ return $parent ? scalar(grep {$_ eq $parent} @subc) : @subc;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 3 2 5
291 }
292  
293 sub rehash_subclasses {
294 1 ▶ %subclasses = _read_map_files('subclasses', 'LIST');
Subroutine rehash_subclasses: called CC=1 SCAR=0.0
Pod documented
295 1 $_hashed_subclasses++;
296 }
297  
298 9 1;
299  
300 __END__
« MimeInfo/Magic.pm ↑ Summary