Skip to content

Instantly share code, notes, and snippets.

View ian-kent's full-sized avatar

Ian Kent ian-kent

View GitHub Profile
@ian-kent
ian-kent / gist:5952536
Created July 8, 2013 21:12
Example use case of internal forwarding
package RouteTest;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Documentation browser under "/perldoc"
$self->plugin('PODRenderer');
@ian-kent
ian-kent / gist:5973234
Last active December 19, 2015 14:59
Mojolicious route blocking further calls to itself
package EventTest;
use Mojo::Base 'Mojolicious';
#use EV;
use AnyEvent;
# Call /wait1 and /wait2, both block but both get handled asynchronously
# Call /wait1 and another /wait1, the first request blocks the second
# Regardless of above, calling /nowait always works
@ian-kent
ian-kent / gist:5973339
Created July 11, 2013 07:38
Mojolicious lite app which blocks
use Mojolicious::Lite;
use EV;
use AnyEvent;
hook after_build_tx => sub {
print "AFTER BUILD TX\n";
};
get '/' => sub {
my $self = shift;
use Mojolicious::Lite;
use EV;
use AnyEvent;
hook after_build_tx => sub {
print "AFTER BUILD TX\n";
};
get '/' => sub {
my $self = shift;
use Mojolicious::Lite;
use POSIX qw( strftime );
use Test::Mojo;
use Data::Dumper;
use Test::More;
hook after_build_tx => sub {
# print "AFTER BUILD TX\n";
};
@ian-kent
ian-kent / gist:6002248
Created July 15, 2013 18:32
Xslate segfault when using nested blessed objects
package helper;
sub new {
my ($package, %args) = @_;
return bless {
%args
}, 'helper';
}
sub test {
@ian-kent
ian-kent / gist:6002258
Created July 15, 2013 18:33
No segfault in xslate when using a single level of blessed hash
package helper;
sub new {
my ($package, %args) = @_;
return bless {
%args
}, 'helper';
}
sub test {
@ian-kent
ian-kent / macro.pl
Created July 15, 2013 18:39
Xslate undefined function error with blessed object capturing macro
package main;
use Data::Dumper;
use Text::Xslate;
my $count = 0;
my $macro = undef;
my $xslate = Text::Xslate->new(
cache => 1,
function => {
@ian-kent
ian-kent / gist:6002917
Last active December 19, 2015 18:59
Text xslate undefined function with virtual templates
package main;
use Data::Dumper;
use Text::Xslate;
my $count = 0;
my $macro = undef;
my $xslate = Text::Xslate->new(
path => {
'test.tx' => qq{
@ian-kent
ian-kent / also errors.pl
Created July 15, 2013 21:23
Some examples - working, erroring and segfaulting
package obj2;
sub new { my ($package, %args) = @_; bless { %args }, 'obj2' };
sub render { shift->{obj}->() };
package obj;
sub new { bless {}, 'obj' };
sub capture { return obj2->new(obj => pop) }
package main;