| 1 | package Dancer::MIME; | ||||||||||||||||||||||||||||||||||
| 2 | 231 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: Singleton object to handle MimeTypes | ||||||||||||||||||||||||||||||||||
| 4 | 231 | $Dancer::MIME::VERSION = '1.3522'; | |||||||||||||||||||||||||||||||||
| 5 | 231 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 231 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 231 | ▶ | use base 'Dancer::Object::Singleton'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 231 | ▶ | use Dancer::Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 231 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 231 | ▶ | use MIME::Types; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | # Initialise MIME::Types at compile time, to ensure it's done before | ||||||||||||||||||||||||||||||||||
| 15 | # the fork in a preforking webserver like mod_perl or Starman. Not | ||||||||||||||||||||||||||||||||||
| 16 | # doing this leads to all MIME types being returned as "text/plain", | ||||||||||||||||||||||||||||||||||
| 17 | # as MIME::Types fails to load its mappings from the DATA handle. See | ||||||||||||||||||||||||||||||||||
| 18 | # t/04_static_file/003_mime_types_reinit.t and GH#136. | ||||||||||||||||||||||||||||||||||
| 19 | 231 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 231 | MIME::Types->new(only_complete => 1); | |||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 231 | __PACKAGE__->attributes( qw/mime_type custom_types/ ); | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 18 | ▶ | sub init { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 26 | 18 | my ($class, $instance) = @_; | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 18 | $instance->mime_type(MIME::Types->new(only_complete => 1)); | |||||||||||||||||||||||||||||||||
| 29 | 18 | $instance->custom_types({}); | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 8 | ▶ | sub default { | ||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 33 | 8 | my $instance = shift; | |||||||||||||||||||||||||||||||||
| 34 | 8 | ▶ | return Dancer::Config::setting("default_mime_type") || "application/data"; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
Dancer::Config::setting('default_mime_type') || 'application/data'
MC/DC100%1/1
Dancer::Config::setting('default_mime_type') || 'application/data'
Dancer::Config::setting('default_mime_type')
Truth table100%2/2
A
A= Dancer::Config::setting('default_mime_type')
| |||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | sub add_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
add_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 38 | 6 | my ($self, $name, $type) = @_; | |||||||||||||||||||||||||||||||||
| 39 | 6 | $self->custom_types->{$name} = $type; | |||||||||||||||||||||||||||||||||
| 40 | 6 | return; | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | sub add_alias { | ||||||||||||||||||||||||||||||||
|
Subroutine
add_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 44 | 4 | my($self, $alias, $orig) = @_; | |||||||||||||||||||||||||||||||||
| 45 | 4 | my $type = $self->for_name($orig); | |||||||||||||||||||||||||||||||||
| 46 | 4 | $self->add_type($alias, $type); | |||||||||||||||||||||||||||||||||
| 47 | 4 | return $type; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 17 | ▶ | sub for_file { | ||||||||||||||||||||||||||||||||
|
Subroutine
for_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 51 | 17 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||||||||
| 52 | 17 | my ($ext) = $filename =~ /\.([^.]+)$/; | |||||||||||||||||||||||||||||||||
| 53 | 17 | ▶ | return $self->default unless $ext; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 54 | 17 | return $self->for_name($ext); | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 26 | ▶ | sub name_or_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
name_or_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 58 | 26 | my($self, $name) = @_; | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 26 | ▶ | return $name if $name =~ m{/}; # probably a mime type | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 3 | return $self->for_name($name); | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 31 | ▶ | sub for_name { | ||||||||||||||||||||||||||||||||
|
Subroutine
for_name: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 65 | 31 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||
| 66 | 31 | ▶ | return $self->custom_types->{lc $name} || $self->mime_type->mimeTypeOf(lc $name) || $self->default; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->custom_types->{lc $name} || $self->mime_type->mimeTypeOf(lc $name) || $self->default
$self->custom_types->{lc $name} or $self->mime_type->mimeTypeOf(lc $name)
MC/DC0%0/3
$self->custom_types->{lc $name} || $self->mime_type->mimeTypeOf(lc $name) || $self->default
$self->custom_types->{lc $name}
$self->mime_type->mimeTypeOf(lc $name)
$self->default
Truth table75%3/4
A or B || C
A= $self->custom_types->{lc $name}B= $self->mime_type->mimeTypeOf(lc $name)C= $self->default
| |||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 231 | 42; | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||