Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2017 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2447fab3e1588c8450c04c4a21a3eba1 to your computer and use it in GitHub Desktop.
Save anonymous/2447fab3e1588c8450c04c4a21a3eba1 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
# The Lite application
package Lite;
use Mojolicious::Lite;
get '/addr' => \&main::app_addr;
# The Full application
package Full;
use Mojo::Base 'Mojolicious';
sub startup {
my $r = shift->routes;
$r->get( '/addr', \&main::app_addr );
};
package main;
use Data::Dumper;
# The sub which returns application address
sub app_addr {
my $c = shift;
$c->render( text => $c->app."" );
}
use Test::More;
use Test::Mojo;
my $r = app->routes;
$r->any('/l1')->detour( 'Lite' );
$r->any('/l2')->detour( 'Lite' );
$r->any('/f1')->detour( 'Full' );
$r->any('/f2')->detour( 'Full' );
my $t = Test::Mojo->new;
my $t2 = Test::Mojo->new(Lite::app);
my $addr1 = $t->get_ok('/l1/addr')->tx->res->body;
my $addr2 = $t2->get_ok('/l2/addr')->tx->res->body;
ok $addr1 ne $addr2, "Different instances";
$addr1 = $t->get_ok('/f1/addr')->tx->res->body;
$addr2 = $t->get_ok('/f2/addr')->tx->res->body;
ok $addr1 ne $addr2, "Different instances";
done_testing;
__END__
$ perl -Ilib t/mojolicious/lite_vs_full.t
ok 1 - GET /l1/addr
ok 2 - GET /l2/addr
not ok 3 - Different instances
# Failed test 'Different instances'
# at t/mojolicious/nested2.t line 38.
ok 4 - GET /f1/addr
ok 5 - GET /f2/addr
ok 6 - Different instances
1..6
# Looks like you failed 1 test of 6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment