Skip to content

Instantly share code, notes, and snippets.

Eugen Konkov KES777

Block or report user

Report or block KES777

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View format.t
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 {
KES777 / t-mojolicoius-exception_lite_app.t
Created Mar 30, 2018
Mojolicous expects wrong results
View t-mojolicoius-exception_lite_app.t
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');
KES777 / gist:0eec79515ef1c2c5c200ca902c9915ec
Last active Mar 27, 2018
proper descrition of current behaviour
View gist:0eec79515ef1c2c5c200ca902c9915ec
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
get '/test' => { format => 'xxx' };
my $t = Test::Mojo->new;
View gist:1d3e4a5fa342c906f2ea5fde3bb165b9
Initial problem:
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
get '/test' => { format => 'xxx' };
my $t = Test::Mojo->new;
View gist:c7b9a2487b98dee19a329102844a1159
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
KES777 / content_negotiation.t
Created Mar 23, 2018
Content negotiation tests
View content_negotiation.t
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
app->defaults( format => 'zzz', template => 'test' );
get '/app';
get '/route' => { format => 'xxx' };
KES777 / gist:8f6a32b9cde4404414aadffa8fb2515b
Created Mar 23, 2018
format precedence while content negotiation
View gist:8f6a32b9cde4404414aadffa8fb2515b
>Rails picks up the expected format from the query parameter format, or if not there from the URL path suffix, or it not there from the Accept header
Blog post:
>format query parameter is useful for rendering JSON output from a web browser without
special tools to modify the Accept header
IBM knowledge base:
>However, if a request uses multiple methods simultaneously,
KES777 /
Created Mar 3, 2018
Mojolicious Theming
sub startup {
$app->hook( before_render => sub{
my( $c, $args ) = @_;
my $theme = $c->stash->{ theme } // '';
$args->{template} = "$theme/$args->{template}";
# But here we get two problems:
View patch.diff
diff --git a/lib/Mojolicious/ b/lib/Mojolicious/
index cf3cd04..21277fb 100644
--- a/lib/Mojolicious/
+++ b/lib/Mojolicious/
@@ -46,9 +46,6 @@ sub import {
plugin => sub { $app->plugin(@_) },
under => sub { $routes = $root->under(@_) };
- # Make sure there's a default application for testing
- Mojo::UserAgent::Server->app($app) unless Mojo::UserAgent::Server->app;
KES777 / lite_app.t
Last active Nov 3, 2017
not workint mojolicious lite app
View lite_app.t
use Mojolicious::Lite;
package Lite;
use Mojolicious::Lite;
get '/bye' => sub{ shift->render( text => 'OK' ) };
package main;
You can’t perform that action at this time.