WE/Util/MIME.pm

filter: Statementstmt 56.0% 14 / 25 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 41.8% 18 / 43 CC 7 SCAR 36.8
CC
7
Cov
39%
get_mime_type_by_filename
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 39.5
« WE/DB/ComplexUser/AuthUnix.pm ↑ Summary WE_Frontend/Plugin/Teaser.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: MIME.pm,v 1.3 2003/01/19 14:31:09 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2002 Slaven Rezic. All rights reserved.
8 # This package is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
13 #
14  
15 package WE::Util::MIME;
16 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use vars qw($VERSION %mime_types @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
21 1 @EXPORT = qw(get_mime_type_by_filename);
22 1 @EXPORT_OK = qw(%mime_types);
23  
24 # just a fallback...
25 1 %mime_types = ("text/html" => [qw/html htm/],
26 "text/plain" => [qw/txt text/],
27 "image/gif" => [qw/gif/],
28 "image/jpeg" => [qw/jpg jpeg/],
29 "image/png" => [qw/png/],
30 "image/x-xpixmap" => [qw/xpm/],
31 );
32  
33 0 ▶sub get_mime_type_by_filename {
Subroutine get_mime_type_by_filename: not called CC=7 SCAR=40.3
Pod documented
34 0 my $filename = shift;
35 0 (my $ext = $filename) =~ s/^(.+)\.([^.]+)$/$2/;
36 0 ▶ if (eval 'require MIME::Types; 1') {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require MIME::Types; 1") 0 0 0
37 0 my($mime_type) = MIME::Types::by_suffix($ext);
38 0 ▶ return $mime_type if defined $mime_type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mime_type 0 0 0
39 }
40 # fallback...
41 0 scalar keys %mime_types; # reset iterator
42 0 ▶ while(my($mimetype,$exts) = each %mime_types) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %WE::Util::MIME::mime_types) 0 0 0
43 0 foreach my $search_ext (@$exts) {
44 0 ▶ if ($ext eq $search_ext || lc($ext) eq $search_ext) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext eq $search_ext or lc $ext eq $search_ext) 0 0 0
Condition0%0/3
$ext eq $search_ext or lc $ext eq $search_ext
l!l&&r!l&&!r
000
MC/DC0%0/2
$ext eq $search_ext or lc $ext eq $search_ext
$ext eq $search_ext lc $ext eq $search_ext
Truth table0%0/3
A or B
A= $ext eq $search_extB= lc $ext eq $search_ext
ABresult
1X1
011
000
45 0 return $mimetype;
46 }
47 }
48 }
49 0 "application/octet-stream";
50 }
51  
52 1 1;
53  
54 __END__
« WE/DB/ComplexUser/AuthUnix.pm ↑ Summary WE_Frontend/Plugin/Teaser.pm »