| 1 | # Copyrights 1999-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution MIME::Types. Meta-POD processed with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package MIME::Types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | $VERSION = '2.23'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use MIME::Type (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | my %typedb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | sub new(@) { (bless {}, shift)->init( {@_} ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub init($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | keys %typedb or $self->_read_db($args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _read_db($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_db: called CC=18 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my $skip_extensions = $args->{skip_extensions}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | my $only_complete = $args->{only_complete}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | my $only_iana = $args->{only_iana}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | my $db = $ENV{PERL_MIME_TYPE_DB} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | || $args->{db_file} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | || File::Spec->catfile(dirname(__FILE__), 'types.db'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$ENV{'PERL_MIME_TYPE_DB'} || $args->{'db_file'} || 'File::Spec'->catfile(dirname(__FILE__), 'types.db')
$ENV{"PERL_MIME_TYPE_DB"} or $args->{"db_file"}
MC/DC0%0/3
$ENV{'PERL_MIME_TYPE_DB'} || $args->{'db_file'} || 'File::Spec'->catfile(dirname(__FILE__), 'types.db')
$ENV{"PERL_MIME_TYPE_DB"}
$args->{"db_file"}
'File::Spec'->catfile(dirname(__FILE__), 'types.db')
Truth table25%1/4
A or B || C
A= $ENV{"PERL_MIME_TYPE_DB"}B= $args->{"db_file"}C= 'File::Spec'->catfile(dirname(__FILE__), 'types.db')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | local *DB; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | open DB, '<:encoding(utf8)', $db | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | or die "cannot open type database in $db: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 192 | { my $header = <DB>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 192 | ▶ | defined $header or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 188 | chomp $header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # This logic is entangled with the bin/collect_types script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 188 | my ($count, $major, $is_iana, $has_ext) = split /\:/, $header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 188 | ▶ | my $skip_section = $major eq 'EXTENSIONS' ? $skip_extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$only_iana and not $is_iana or $only_complete and not $has_ext
$only_iana and not $is_iana
$only_complete and not $has_ext
MC/DC0%0/4
$only_iana and not $is_iana or $only_complete and not $has_ext
$only_iana
not $is_iana
$only_complete
not $has_ext
Truth table14%1/7
A and not(B) or C and not(D)
A= $only_ianaB= not $is_ianaC= $only_completeD= not $has_ext
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | : (($only_iana && !$is_iana) || ($only_complete && !$has_ext)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | #warn "Skipping section $header\n" if $skip_section; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 188 | (my $section = $major) =~ s/^x-//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 188 | ▶ | if($major eq 'EXTENSIONS') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | { local $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | while(<DB>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 9016 | ▶ | { last if m/^$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 9012 | ▶ | next if $skip_section; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 9012 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 9012 | ▶ | $typedb{$section}{$1} = $2 if m/(.*);(.*)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 184 | { local $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 184 | ▶ | while(<DB>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 12456 | ▶ | { last if m/^$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12272 | ▶ | next if $skip_section; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 12272 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12272 | ▶ | $typedb{$section}{$1} = "$major/$_" if m/^(?:x-)?([^;]+)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | close DB; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Catalyst-Plugin-Static-Simple uses it :( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | sub create_type_index {} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_type_index: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub type($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4157 | ▶ | { my $spec = lc $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4157 | ▶ | $spec = 'text/plain' if $spec eq 'text'; # old mailers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4157 | ▶ | $spec =~ m!^(?:x\-)?([^/]+)/(?:x-)?(.*)! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4157 | ▶ | my $section = $typedb{$1} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4157 | ▶ | my $record = $section->{$2} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4157 | ▶ | return $record if ref $record; # already extended | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2078 | my $simple = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2078 | my ($type, $ext, $enc) = split m/\;/, $record; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2078 | my $os = undef; # XXX TODO | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2078 | $section->{$simple} = MIME::Type->new | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ( type => $type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | , extensions => [split /\,/, $ext] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | , encoding => $enc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | , system => $os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub mimeTypeOf($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 25 | ▶ | { my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mimeTypeOf: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 25 | (my $ext = lc $name) =~ s/.*\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 25 | ▶ | my $type = $typedb{EXTENSIONS}{$ext} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | $self->type($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | sub addType(@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addType: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | foreach my $type (@_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | { my ($major, $minor) = split m!/!, $type->simplified; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | $typedb{$major}{$minor} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | $typedb{EXTENSIONS}{$_} = $type for $type->extensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | sub types() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
types: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | foreach my $section (keys %typedb) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | { next if $section eq 'EXTENSIONS'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | push @types, map $_->type("$section/$_"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | sort keys %{$typedb{$section}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub listTypes() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listTypes: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | my @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6 | foreach my $section (keys %typedb) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 138 | ▶ | { next if $section eq 'EXTENSIONS'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 132 | foreach my $sub (sort keys %{$typedb{$section}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 18246 | { my $record = $typedb{$section}{$sub}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 18246 | ▶ | push @types, ref $record ? $record->type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | : $record =~ m/^([^;]+)/ ? $1 : die; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub extensions { keys %{$typedb{EXTENSIONS}} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extensions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub _MojoExtTable() {$typedb{EXTENSIONS}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_MojoExtTable: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | #------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub httpAccept($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
httpAccept: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | my @listed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | foreach (split /\,\s*/, shift) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | m!^ ([a-zA-Z0-9-]+ | \*) / ( [a-zA-Z0-9+-]+ | \* ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | \s* (?: \;\s*q\=\s* ([0-9]+(?:\.[0-9]*)?) \s* )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | (\;.* | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | $ !x or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 17 | my $mime = "$1/$2$4"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 17 | ▶ | my $q = defined $3 ? $3 : 1; # q, default=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # most complex first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 17 | ▶ | $q += $4 ? +0.01 : $1 eq '*' ? -0.02 : $2 eq '*' ? -0.01 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # keep order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 17 | $q -= @listed*0.0001; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 17 | push @listed, [ $mime => $q ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | map $_->[0], sort {$b->[1] <=> $a->[1]} @listed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | sub httpAcceptBest($@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
httpAcceptBest: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | ▶ | my @accept = ref $_[0] eq 'ARRAY' ? @{(shift)} : $self->httpAccept(shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | my $match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | foreach my $acc (@accept) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | { $acc =~ s/\s*\;.*//; # remove attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 17 | ▶ | my $m = $acc !~ s#/\*$## ? first { $_->equals($acc) } @_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | : $acc eq '*' ? $_[0] # $acc eq */* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | : first { $_->mediaType eq $acc } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | return $m if defined $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub httpAcceptSelect($@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | ▶ | { my ($self, $accept) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
httpAcceptSelect: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | ▶ | my $fns = !@_ ? return () : ref $_[0] eq 'ARRAY' ? shift : [@_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | ▶ | unless(defined $accept) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | { my $fn = $fns->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | return ($fn, $self->mimeTypeOf($fn)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # create mapping type -> filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | my (%have, @have); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | foreach my $fn (@$fns) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 6 | ▶ | { my $type = $self->mimeTypeOf($fn) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | $have{$type->simplified} = $fn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 6 | push @have, $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | my $type = $self->httpAcceptBest($accept, @have); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 3 | ▶ | defined $type ? ($have{$type}, $type) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # OLD INTERFACE (version 0.06 and lower) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | our @EXPORT_OK = qw(by_suffix by_mediatype import_mime_types); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | my $mime_types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub by_suffix($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 7 | ▶ | { my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
by_suffix: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | ▶ | $mime_types ||= MIME::Types->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$mime_types ||= "MIME::Types"->new
MC/DC0%0/2
$mime_types ||= "MIME::Types"->new
$mime_types
"MIME::Types"->new
Truth table66%2/3
A ||= B
A= $mime_typesB= "MIME::Types"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | my $mime = $mime_types->mimeTypeOf($filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | ▶ | my @data = defined $mime ? ($mime->type, $mime->encoding) : ('',''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | wantarray ? @data : \@data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | sub by_mediatype($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | { my $type = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
by_mediatype: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 8 | ▶ | $mime_types ||= MIME::Types->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mime_types ||= "MIME::Types"->new
MC/DC0%0/2
$mime_types ||= "MIME::Types"->new
$mime_types
"MIME::Types"->new
Truth table33%1/3
A ||= B
A= $mime_typesB= "MIME::Types"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | my @found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | if(!ref $type && index($type, '/') >= 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $type and index($type, "/") != -1
MC/DC100%2/2
not ref $type and index($type, "/") != -1
not ref $type
index($type, "/") != -1
Truth table100%3/3
not(A) and B
A= not ref $typeB= index($type, "/") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | { my $mime = $mime_types->type($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | @found = $mime if $mime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | ▶ | { my $search = ref $type eq 'Regexp' ? $type : qr/$type/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | @found = map $mime_types->type($_), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | grep $_ =~ $search, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | $mime_types->listTypes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 8 | my @data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 8 | foreach my $mime (@found) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4126 | { push @data, map [$_, $mime->type, $mime->encoding], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $mime->extensions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 8 | ▶ | wantarray ? @data : \@data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | sub import_mime_types($) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | { my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import_mime_types: not called CC=1 SCAR=0.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | croak <<'CROAK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | import_mime_types is not supported anymore: if you have types to add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | please send them to the author. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | CROAK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||