This file contains hidden or 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
sub _exception { | |
my ($next, $c) = @_; | |
local $SIG{__DIE__} | |
= sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) }; | |
$c->render_exception($@) unless eval { $next->(); 1 }; | |
} |
This file contains hidden or 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
use Mojolicious::Lite; | |
use Mojo::JSON::XS; | |
... | |
app->renderer->add_handler(json => sub { | |
my ($self, $c, $output, $options) = @_; | |
$$output = Mojo::JSON::XS->new->encode($options->{json}); | |
}); |
This file contains hidden or 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
var is_array = function(value) { | |
return value && | |
typeof value === 'object' && | |
typeof value.length === 'number' && | |
typeof value.splice === 'function' && | |
!(value.propertyIsEnumerable('length')); | |
} | |
function parse_param(params) { | |
var build_hash; |
This file contains hidden or 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
use strict; | |
use warnings; | |
use POSIX qw( SIGKILL ); | |
my $TIMEOUT = 10; | |
my $cmd = "sleep 15"; | |
my $pid = fork(); | |
if (!defined($pid)) { die "failed to fork"; } | |
if ($pid == 0) { |
This file contains hidden or 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
use strict; | |
use warnings; | |
use File::Basename; | |
use Mojo::Server::Daemon; | |
use Test::TCP; | |
use Test::More; | |
use Test::Mojo; | |
my $t = Test::Mojo->new('SampleApp'); |
This file contains hidden or 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
# タイムアウト設定 | |
$poll->poll($timeout); | |
# Read OKとなったハンドルに対してコールバックを実行 | |
++$i and $self->_sandbox('Read', $self->{io}{fileno $_}{cb}, 0) | |
for $poll->handles(POLLIN | POLLPRI | POLLHUP | POLLERR); | |
# Write OKとなったハンドルに対してコールバックを実行 | |
++$i and $self->_sandbox('Write', $self->{io}{fileno $_}{cb}, 1) | |
for $poll->handles(POLLOUT); |
This file contains hidden or 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
#include <stdio.h> | |
int main() | |
{ | |
char buf[80]; | |
int a, b; | |
fgets(buf, 80, stdin); | |
sscanf(buf, "%d %d", &a, &b); |
This file contains hidden or 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
JSON文字列に変換する + utf8フラグを外す |
This file contains hidden or 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
use strict; | |
use warnings; | |
use utf8; | |
use Test::More; | |
use Test::Mojo; | |
use File::Basename; | |
$ENV{MOJO_HOME} = dirname(__FILE__) . '/../'; | |
require "$ENV{MOJO_HOME}/myapp.pl"; |
This file contains hidden or 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
$ morbo script/myapp # Mojoliciousアプリの場合 | |
$ morbo myapp.pl # Mojolicious::Liteアプリの場合 |