Last active
November 3, 2017 11:57
-
-
Save KES777/1f5fafe6b4c61091e18d4d4b8e90cd2b to your computer and use it in GitHub Desktop.
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::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; | |
# Mojolicous reuse lite application instance | |
my $addr1 = $t->get_ok('/l1/addr')->tx->res->body; | |
my $addr2 = $t->get_ok('/l2/addr')->tx->res->body; | |
ok $addr1 ne $addr2, "Different instances"; | |
# But create two instances when application is full | |
$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; | |
# The sub which returns application address | |
sub get_app_addr { | |
my $c = shift; | |
$c->render( text => $c->app."" ); | |
} | |
# The Lite application | |
package Lite; | |
use Mojolicious::Lite; | |
get '/addr' => \&main::get_app_addr; | |
__END__ | |
# The Full application | |
package Full; | |
use Mojo::Base 'Mojolicious'; | |
sub startup { shift->routes->get( '/addr', \&main::get_app_addr ) }; | |
$ perl -Ilib t/mojolicious/lite_vs_full.t | |
ok 1 - GET /l1/addr | |
ok 2 - GET /l2/addr | |
ok 3 - Different instances | |
ok 4 - GET /f1/addr | |
ok 5 - GET /f2/addr | |
ok 6 - Different instances | |
1..6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment