This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Test::Mojo; | |
use Test::More; | |
app->defaults( format => 'zzz', template => 'test' ); | |
get '/app'; | |
get '/route' => { format => 'xxx' }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mojolicious content negotiation gotchas | |
Let's begin with parts which participate in content negotiation. | |
First of all there are client requirements and server capabilities. | |
This is obvious that we should prefer client requirements over server capabilies by default. And, if server (controller's action) wants, it may force {format}. | |
So picture is next by precedence: | |
1. Controller's action format preferences |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initial problem: | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
use Test::More; | |
get '/test' => { format => 'xxx' }; | |
my $t = Test::Mojo->new; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DESCRIPTION OF THE PROBLEM | |
use Mojolicious::Lite; | |
use Test::Mojo; | |
use Test::More; | |
get '/test' => { format => 'xxx' }; | |
my $t = Test::Mojo->new; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Test::Mojo; | |
use Test::More; | |
hook before_render => sub { | |
my ($c, $args) = @_; | |
@$args{qw(text format)} = ($args->{exception}, 'txt') | |
if ($args->{template} // '') eq 'exception' && $c->accepts('txt'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::Base -strict; | |
use Test::Mojo; | |
use Test::More; | |
use Mojolicious::Lite; | |
app->defaults( handler => 'my_handler' ); | |
get '/example' => sub{ die }; | |
hook before_render => sub { |
OlderNewer