Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created October 20, 2016 11:55
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 brianmed/731f72ee6c7d4857d994479b17d32b00 to your computer and use it in GitHub Desktop.
Save brianmed/731f72ee6c7d4857d994479b17d32b00 to your computer and use it in GitHub Desktop.
Shared logic in mojolicious lite app
use Mojolicious::Lite;
require SharedPkg;
get '/' => sub {
my $c = shift;
$c->render(template => 'index', joy => $SharedPkg::variable);
};
app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>
<head><title>News</title></head>
<body>Admin: <%= $joy %></body>
</html>
use Mojolicious::Lite;
require SharedPkg;
get '/' => sub {
my $c = shift;
$c->render(template => 'index', joy => $SharedPkg::variable);
};
app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>
<head><title>News</title></head>
<body>News: <%= $joy %></body>
</html>
use Mojolicious::Lite;
plugin Mount => {'127.0.0.1/news' => './app_news.pl'};
plugin Mount => {'127.0.0.1/admin' => './app_admin.pl'};
get '/' => sub {
my $c = shift;
$c->render(text => "Hello");
};
app->start;
package SharedPkg;
our $variable = "Joy";
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment