Skip to content

Instantly share code, notes, and snippets.

View Akron's full-sized avatar

Nils Diewald Akron

View GitHub Profile
@Akron
Akron / Mojolicious::Plugin::Wordlist.pm
Created May 19, 2011 16:46
Unexpected behaviour when reregistering plugins
package Mojolicious::Plugin::Wordlist;
use Mojo::Base 'Mojolicious::Plugin';
sub register {
my ($plugin, $mojo) = @_;
$plugin->{text} = "Wordlist:\n";
$mojo->helper(
'words' => sub {
@Akron
Akron / gist:1014751
Created June 8, 2011 16:20
Sample Mojo-App with route-Shortcut
package Mojolicious::Plugin::Test;
use Mojo::Base 'Mojolicious::Plugin';
sub register {
my ($plugin, $mojo) = @_;
$mojo->routes->add_shortcut(
'test' => sub {
my $route = shift;
$route->name('test');
# What are the wildcards?
@Akron
Akron / gist:1164293
Created August 23, 2011 03:39
Add_shortcut goes wrong ...?
#/usr/bin/env perl
package Test;
use Mojo::Base 'Mojolicious';
sub startup {
my $m = shift;
my $r = $m->routes;
$r->add_shortcut(
use Mojolicious::Routes;
my $r = Mojolicious::Routes->new('/(:user)');
print join(',',@{$r->pattern->symbols});
@Akron
Akron / gist:1216847
Created September 14, 2011 15:16
Render in advance
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
$c->write_chunk('hi',
sub {
# New c not necessary
$c->finish;
sleep(3);
$c->app->log->debug('check');
@Akron
Akron / gist:1265535
Created October 5, 2011 20:09
Tidy up when guests are gone
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
$c->render_text('Hallo!');
$c->on_finish(
sub {
my $c = shift;
sleep(3);
@Akron
Akron / gist:1314239
Created October 25, 2011 20:57
Tidy up when guests are gone (write cb)
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
$c->res->headers->content_length(5);
$c->write(
'Hallo' => sub {
my $c = shift;
sleep(3);
@Akron
Akron / gist:1376998
Created November 18, 2011 16:45
Filtering in Mojolicious
# Some values.
my ($a, $b, $c) = ('hallo', 'foo', 'bar');
# Emit a filter hook
$c->filter(
'on_database_access' =>
\$a, \$b, \$c =>
sub { # Do whenever all subscribers are done.
print $a,"\n";
}
@Akron
Akron / gist:1377904
Created November 18, 2011 22:00
Filter Plugin
package Mojolicious::Plugin::Filter;
use Mojo::Base 'Mojolicious::Plugin';
# Register plugin
sub register {
my ($plugin, $mojo) = @_;
my %filters;
# Filter helper
@Akron
Akron / gist:1377960
Created November 18, 2011 22:23
Filter Plugin 2 - with Closure
package Mojolicious::Plugin::Filter2;
use Mojo::Base 'Mojolicious::Plugin';
# Register plugin
sub register {
my ($plugin, $mojo) = @_;
my %filters;
# Filter helper