Mojolicious offers Helpers of Mojolicious::Guides::Tutorial which are functions which you setup during startup. I am not sure if this is a good way, but I would do something like:
use Mojo::Base 'Mojolicious'; # This method will run once at server start sub startup { my $self = $_[0]; $self->app->config( hypnotoad => { listen => ['http://'.$SERVER_ADDRESS.':'.$SERVER_PORT] } ); my $DOCUMENT_ROOT = '...'; $self->helper(document_root => sub { $DOCUMENT_ROOT }); # I also add a logger object my $logger = Mojo::Log->new; $self->helper(applog => sub { $logger }); ... }
And at any route endpoint (in its own separate file):
use Mojo::Base 'Mojolicious::Controller'; sub logout { my $c = $_[0]; my $log = $c->applog; my $dr = $c->document_root; ... $c->render(...) return 1; }
There is also Mojolicious::Plugin::DefaultHelpers with some helpers before reinventing the wheel
FWIW, the template system I use is Text::Xslate via MojoX::Renderer::Xslate. It's surely idiosyncratic and the language associated with it is aptly named Kolon! I *think* I heard choroba saying that it was quite fast when I was looking around. And I use it for 3 years now, quite happy and with colon painless.
bw, bliako
In reply to Re^5: Mojolicious with Template Toolkit
by bliako
in thread Mojolicious with Template Toolkit
by hippo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |