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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.