Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Logioniz / ua.bad.pl
Created November 2, 2014 13:39
UserAgent in controller
my $ua = Mojo::UserAgent->new();
my $result;
$self->render_later;
$ua->head( $location => sub {
my ($ua, $tx) = @_;
if ( $tx->res->code eq '200' ) {
$result = 'good';
}
@Logioniz
Logioniz / ioloop.pl
Last active August 29, 2015 14:08
Nice example to understand ioloop.
my $t = Test::Mojo->new;
sub f2 {
my $cb = shift;
my $d = Mojo::IOLoop->delay(
sub {
warn 'f2_1', $/;
shift->pass;
},
sub {
@Logioniz
Logioniz / next_tick_a.pl
Last active August 29, 2015 14:08
Nice example. Why die?)
#!/usr/bin/perl -wl
# code for answer on question
use Mojo::IOLoop;
sub inc {
my ($num, $cb) = @_;
return Mojo::IOLoop->next_tick(sub {$cb->('error')}) unless $num =~ /^\d+$/;