Skip to content

Commit

Permalink
mention why multiple MIME types are ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 21, 2012
1 parent 556acd1 commit 6e73c51
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.86 2012-04-21
2.86 2012-04-22
- Added support for TO_JSON method to Mojo::JSON.
- Improved Mojo::Template exception handling.
- Improved documentation.
Expand Down
15 changes: 7 additions & 8 deletions lib/Mojo.pm
Expand Up @@ -27,11 +27,11 @@ sub new {
my $self = shift->SUPER::new(@_);

# Detect home directory
$self->home->detect(ref $self);
my $home = $self->home->detect(ref $self);

# Log directory
$self->log->path($self->home->rel_file('log/mojo.log'))
if -w $self->home->rel_file('log');
$self->log->path($home->rel_file('log/mojo.log'))
if -w $home->rel_file('log');

return $self;
}
Expand All @@ -47,15 +47,14 @@ sub _dict {
my ($self, $name) = (shift, shift);

# Hash
$self->{$name} ||= {};
return $self->{$name} unless @_;
my $dict = $self->{$name} ||= {};
return $dict unless @_;

# Get
return $self->{$name}{$_[0]} unless @_ > 1 || ref $_[0];
return $dict->{$_[0]} unless @_ > 1 || ref $_[0];

# Set
my $values = ref $_[0] ? $_[0] : {@_};
$self->{$name} = {%{$self->{$name}}, %$values};
%$dict = (%$dict, %{ref $_[0] ? $_[0] : {@_}});

return $self;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -46,8 +46,7 @@ package $class;
EOF
die qq/"$file" is not a valid application.\n/
unless blessed $app && $app->isa('Mojo');
$self->app($app);
return $app;
return $self->app($app)->app;
}

# "Are you saying you're never going to eat any animal again? What about
Expand Down
15 changes: 4 additions & 11 deletions lib/Mojolicious.pm
Expand Up @@ -81,13 +81,8 @@ sub new {
if -w $home->rel_file('log');

# Load default plugins
$self->plugin('HeaderCondition');
$self->plugin('DefaultHelpers');
$self->plugin('TagHelpers');
$self->plugin('EPLRenderer');
$self->plugin('EPRenderer');
$self->plugin('RequestTimer');
$self->plugin('PoweredBy');
$self->plugin($_) for qw/HeaderCondition DefaultHelpers TagHelpers/;
$self->plugin($_) for qw/EPLRenderer EPRenderer RequestTimer PoweredBy/;

# Exception handling
$self->hook(
Expand All @@ -103,8 +98,7 @@ sub new {
$self->log->level('info') unless $mode eq 'development';

# Run mode
$mode = $mode . '_mode';
$self->$mode(@_) if $self->can($mode);
if (my $sub = $self->can("${mode}_mode")) { $self->$sub(@_) }

# Startup
$self->startup(@_);
Expand All @@ -128,8 +122,7 @@ sub dispatch {
my $tx = $c->tx;
$c->res->code(undef) if $tx->is_websocket;
$self->sessions->load($c);
my $plugins = $self->plugins;
$plugins->emit_hook(before_dispatch => $c);
my $plugins = $self->plugins->emit_hook(before_dispatch => $c);

# Try to find a static file
$self->static->dispatch($c);
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -836,7 +836,8 @@ L<Mojo::Message::Response> object.
Automatically select best possible representation for resource from C<Accept>
request header, C<format> stash value or C<format> GET/POST parameter,
defaults to rendering an empty C<204> response. Unspecific C<Accept> request
headers that contain more than one MIME type are ignored.
headers that contain more than one MIME type are currently ignored, since
browsers often don't really know what they actually want.
$c->respond_to(
json => sub { $c->render_json({just => 'works'}) },
Expand Down
28 changes: 9 additions & 19 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -103,23 +103,17 @@ sub render {
@{$stash}{keys %$args} = values %$args;

# Extract important stash values
my $template = delete $stash->{template};
my $format = $stash->{format} || $self->default_format;
my $data = delete $stash->{data};
my $json = delete $stash->{json};
my $text = delete $stash->{text};
my $inline = delete $stash->{inline};

# Pick handler
my $handler = $stash->{handler};
$handler = $self->default_handler if defined $inline && !defined $handler;
my $options = {
template => $template,
format => $format,
handler => $handler,
encoding => $self->encoding,
inline => $inline
handler => $stash->{handler},
template => delete $stash->{template}
};
my $data = $options->{data} = delete $stash->{data};
my $format = $options->{format} = $stash->{format} || $self->default_format;
my $inline = $options->{inline} = delete $stash->{inline};
my $json = $options->{json} = delete $stash->{json};
my $text = $options->{test} = delete $stash->{text};
$options->{handler} //= $self->default_handler if defined $inline;

# Text
my $output;
Expand Down Expand Up @@ -187,14 +181,10 @@ EOF

sub template_name {
my ($self, $options) = @_;

return unless my $template = $options->{template} || '';
return unless my $format = $options->{format};
my $handler = $options->{handler};
my $file = "$template.$format";
$file = "$file.$handler" if defined $handler;

return $file;
return defined $handler ? "$template.$format.$handler" : "$template.$format";
}

sub template_path {
Expand Down
7 changes: 2 additions & 5 deletions lib/Mojolicious/Sessions.pm
Expand Up @@ -9,9 +9,6 @@ has cookie_name => 'mojolicious';
has cookie_path => '/';
has default_expiration => 3600;

# JSON serializer
my $JSON = Mojo::JSON->new;

# "Bender, quit destroying the universe!"
sub load {
my ($self, $c) = @_;
Expand All @@ -21,7 +18,7 @@ sub load {

# Deserialize
$value =~ s/\-/\=/g;
return unless my $session = $JSON->decode(b64_decode $value);
return unless my $session = Mojo::JSON->new->decode(b64_decode $value);

# Expiration
my $expiration = $self->default_expiration;
Expand Down Expand Up @@ -59,7 +56,7 @@ sub store {
if $expiration || $default;

# Serialize
my $value = b64_encode $JSON->encode($session), '';
my $value = b64_encode(Mojo::JSON->new->encode($session), '');
$value =~ s/\=/\-/g;

# Session cookie
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Types.pm
Expand Up @@ -94,7 +94,8 @@ the following ones.
my $ext = $types->detect('application/json;q=9');
Detect file extensions from C<Accept> header value. Unspecific values that
contain more than one MIME type are ignored.
contain more than one MIME type are currently ignored, since browsers often
don't really know what they actually want.
=head2 C<type>
Expand Down

0 comments on commit 6e73c51

Please sign in to comment.