-
-
Save iizukanao/825825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use lib 'lib'; | |
use MyApp; | |
my $app = MyApp->new; | |
$app->setup; | |
$app->handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp; | |
use Ark; | |
__PACKAGE__->meta->make_immutable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp::Controller::Root; | |
use Ark 'Controller'; | |
use AnyEvent; | |
has '+namespace' => default => ''; | |
sub default :Path :Args { | |
my ($self, $c) = @_; | |
$c->res->status(404); | |
$c->res->body('404 Not Found'); | |
} | |
sub index :Path { | |
my ($self, $c) = @_; | |
$c->res->content_type('text/html; charset=utf-8'); | |
$c->res->streaming(sub { | |
my $r = shift; | |
my $i = 0; | |
my $t; $t = AnyEvent->timer( | |
after => 1, | |
interval => 1, | |
cb => sub { | |
eval { | |
$r->write('Hello ' . ++$i. "\n"); | |
if (10 == $i) { | |
undef $t; | |
$r->close; | |
} | |
1; | |
} or do { | |
if ( $! =~ /Broken pipe/ ) { | |
print "client disconnected\n"; | |
} else { | |
print "error: $@\n"; | |
} | |
undef $t; | |
$r->close; | |
}; | |
}, | |
); | |
}); | |
} | |
__PACKAGE__->meta->make_immutable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment