Mojolicious::Plugin::Narada - Narada configuration plugin
This document describes Mojolicious::Plugin::Narada version v1.0.1
# Mojolicious $self->plugin('Narada'); $self->plugin(Narada => (log => Log::Fast->global)); # Mojolicious::Lite plugin 'Narada'; plugin Narada => (log => Log::Fast->global); # Global timer package MyApp; sub startup { my $app = shift; Mojo::IOLoop->timer(0 => $app->proxy(sub { say 'Next tick.' })); } # Request-related timer package MyApp::MyController; sub myaction { my $c = shift; $c->render_later; Mojo::IOLoop->timer(1 => $c->weak_proxy(sub { say 'Alive' })); Mojo::IOLoop->timer(2 => $c->proxy(sub { $c->render(text => 'Delayed by 2 seconds!'); })); Mojo::IOLoop->timer(3 => $c->weak_proxy(sub { say 'Dead' })); }
Mojolicious::Plugin::Narada is a plugin that configure Mojolicious to work in Narada project management environment.
Also this plugin add helpers proxy and weak_proxy, and you MUST use them to wrap all callbacks you setup for handling delayed events like timers or I/O (both global in your app and related to requests in your actions).
proxy
weak_proxy
There is also one feature unrelated to Narada - if callback started by any action throw unhandled exception it will be sent to browser using same $c->reply->exception as it already works for actions without delayed response.
$c->reply->exception
Mojolicious default Mojo::Log replaced with MojoX::Log::Fast to support logging to project-local syslog daemon in addition to files. In most cases it works as drop-in replacement and doesn't require any modifications in user code.
Also it set $app->log->ident() to $c->req->url->path to ease log file analyse.
$app->log->ident()
$c->req->url->path
You should manually add these lines to ./you_app starting script before call to Mojolicious::Commands->start_app():
./you_app
Mojolicious::Commands->start_app()
use Narada::Config qw( get_config_line ); # mode should be set here because it's used before executing MyApp::startup() local $ENV{MOJO_MODE} = get_config_line('mode');
Config file config/cookie.secret automatically loaded and used to initialize $app->secrets() (each line of file became separate param).
config/cookie.secret
$app->secrets()
Config file config/basepath automatically loaded and used to fix $c->req->url->base->path and $c->req->url->path to guarantee their consistency in any environment:
config/basepath
$c->req->url->base->path
url->path doesn't contain base->path
url->path does have leading slash
url->base->path set to content of config/basepath
These config files automatically loaded from config/hypnotoad/* and used to initialize $app->config(hypnotoad):
config/hypnotoad/*
$app->config(hypnotoad)
listen proxy accepts workers
Also hypnotoad configured to keep it lock/pid files in var/.
var/
unlock() will be automatically called after all actions and callbacks, even if they throw unhandled exception.
unlock()
Mojolicious::Plugin::Narada supports the following options.
plugin Narada => (log => Log::Fast->global);
Value for MojoX::Log::Fast->new().
$cb = $app->proxy( $cb ); $cb = $c->proxy( $cb ); $cb = $c->weak_proxy( $cb );
Mojolicious::Plugin::Narada inherits all methods from Mojolicious::Plugin and implements the following new ones.
$plugin->register(Mojolicious->new); $plugin->register(Mojolicious->new, {log => Log::Fast->global});
Register hooks in Mojolicious application.
Narada, MojoX::Log::Fast, Mojolicious.
Please report any bugs or feature requests through the issue tracker at https://github.com/powerman/perl-Mojolicious-Plugin-Narada/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests.
https://github.com/powerman/perl-Mojolicious-Plugin-Narada
git clone https://github.com/powerman/perl-Mojolicious-Plugin-Narada.git
MetaCPAN Search
https://metacpan.org/search?q=Mojolicious-Plugin-Narada
CPAN Ratings
http://cpanratings.perl.org/dist/Mojolicious-Plugin-Narada
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Mojolicious-Plugin-Narada
CPAN Testers Matrix
http://matrix.cpantesters.org/?dist=Mojolicious-Plugin-Narada
CPANTS: A CPAN Testing Service (Kwalitee)
http://cpants.cpanauthors.org/dist/Mojolicious-Plugin-Narada
Alex Efros <powerman@cpan.org>
This software is Copyright (c) 2013- by Alex Efros <powerman@cpan.org>.
This is free software, licensed under:
The MIT (X11) License
To install Mojolicious::Plugin::Narada, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Narada
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Narada
For more information on module installation, please visit the detailed CPAN module installation guide.