Skip to content

Instantly share code, notes, and snippets.

/Example.pm Secret

Created November 14, 2011 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fac672eb7bc967b779da to your computer and use it in GitHub Desktop.
Save anonymous/fac672eb7bc967b779da to your computer and use it in GitHub Desktop.
Mojolicious write_chunk testcase
package Testcase::Example;
use Mojo::Base 'Mojolicious::Controller';
use Time::HiRes qw(sleep);
# This action will render a template
sub welcome {
my $self = shift;
$self->render_later;
$self->res->code(200);
$self->res->headers->content_type('text/plain');
my $next_input;
my $n = 0;
$next_input = sub {
if($n == 150) {
return $self->write_chunk('');
}
$n++;
sleep 0.1;
$self->write_chunk(">> $n <<\n", $next_input);
};
$self->write_chunk("Begin of input!\n", $next_input);
}
1;
package Testcase;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Routes
my $r = $self->routes;
$r->route('/')->to('example#welcome');
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment