Mojolicious::Types - MIME Types


Mojolicious documentation Contained in the Mojolicious distribution.

Index


Code Index:

NAME

Top

Mojolicious::Types - MIME Types

SYNOPSIS

Top

  use Mojolicious::Types;

DESCRIPTION

Top

Mojolicious::Types is a container for MIME types.

ATTRIBUTES

Top

Mojolicious::Types implements the following attributes.

types

  my $map = $types->types;
  $types  = $types->types({png => 'image/png'});

List of MIME types.

METHODS

Top

Mojolicious::Types inherits all methods from Mojo::Base and implements the following ones.

type

  my $type = $types->type('png');
  $types   = $types->type(png => 'image/png');

Get or set MIME type for file extension.

SEE ALSO

Top

Mojolicious, Mojolicious::Guides, http://mojolicio.us.


Mojolicious documentation Contained in the Mojolicious distribution.

package Mojolicious::Types;
use Mojo::Base -base;

# "Once again, the conservative, sandwich-heavy portfolio pays off for the
#  hungry investor."
has types => sub {
  return {
    atom => 'application/atom+xml',
    bin  => 'application/octet-stream',
    css  => 'text/css',
    gif  => 'image/gif',
    gz   => 'application/gzip',
    htm  => 'text/html',
    html => 'text/html;charset=UTF-8',
    ico  => 'image/x-icon',
    jpeg => 'image/jpeg',
    jpg  => 'image/jpeg',
    js   => 'application/x-javascript',
    json => 'application/json',
    mp3  => 'audio/mpeg',
    png  => 'image/png',
    rss  => 'application/rss+xml',
    svg  => 'image/svg+xml',
    tar  => 'application/x-tar',
    txt  => 'text/plain',
    woff => 'application/x-font-woff',
    xml  => 'text/xml',
    zip  => 'application/zip'
  };
};

# "Magic. Got it."
sub type {
  my ($self, $ext, $type) = @_;
  if ($type) {
    $self->types->{$ext} = $type;
    return $self;
  }
  $self->types->{$ext || ''};
}

1;
__END__