File Coverage

blib/lib/Mojolicious/Plugin/MimeTypes.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::MimeTypes;
2 1     1   795 use Mojo::Base 'Mojolicious::Plugin';
  1         3  
  1         5  
3              
4             our $VERSION = '0.03';
5              
6 1     1   210 use MIME::Types;
  1         1  
  1         62  
7 1     1   14 use List::MoreUtils qw(uniq);
  1         1  
  1         12  
8              
9             sub register {
10 1     1 1 37 my ($self, $app) = @_;
11 1         5 my $mts = MIME::Types->new;
12 1         30426 my %types = ();
13 1         9 foreach my $type ( $mts->listTypes ) {
14 2435 50       17114 my $mt = $mts->type($type) or next;
15 2435         101923 foreach my $ext ( sort $mt->extensions ) {
16 2163         5743 push @{$types{lc($ext)}}, $type;
  2163         7178  
17             }
18             }
19 1         1840 foreach my $ext ( sort keys %types ) {
20 1724         63403 $app->types->type($ext => [uniq @{$types{$ext}}]);
  1724         14888  
21             }
22             }
23              
24             1;
25             __END__