Contenu connexe Similaire à 最近作ったN個のCPANモジュール Yokohama.pm #10 Similaire à 最近作ったN個のCPANモジュール Yokohama.pm #10 (20) Plus de Masahiro Nagano (20) 最近作ったN個のCPANモジュール Yokohama.pm #105. use Proclet;
my $proclet = Proclet->new();
$proclet->service(...);
$proclet->service(...);
$proclet->service(
code => sub {
scheduled_work();
},
tag => 'cron',
every => '0 12 * * *', #everyday at 12:00am
);
$proclet->run;
7. Apache::LogFormat::Compiler has a
problem. Twice a year the timezone is
changed because of daylight saving.
A::LF::C ignores this fact and still
shows old timezone after change.
https://github.com/kazeburo/Apache-LogFormat-Compiler/pull/3
dex4er
ALFC、DST(サマータイム)をサポートしてないよ!
8. version < 0.14
local $ENV{TZ} = 'America/New_York';
POSIX::tzset;
my $time = timelocal(0, 0, 1, 3, 11 - 1, 2013);
my $log_handler = Apache::LogFormat::Compiler->new();
my $req = req_to_psgi(GET "/");
my $res = [200,[],[q!OK!]];
print $log_handler->log_line($req,$res,0,2,$time);
print $log_handler->log_line($req,$res,0,2,$time+3599);
print $log_handler->log_line($req,$res,0,2,$time+3600);
時間が戻ってる!
__DATA__
127.0.0.1 - - [03/Nov/2013:01:00:00 -0400] "GET / HTTP/1.1" 200 0 "-" "-"
127.0.0.1 - - [03/Nov/2013:01:59:59 -0400] "GET / HTTP/1.1" 200 0 "-" "-"
127.0.0.1 - - [03/Nov/2013:01:00:00 -0400] "GET / HTTP/1.1" 200 0 "-" "-"
9. version >= 0.14
local $ENV{TZ} = 'America/New_York';
POSIX::tzset;
my $time = timelocal(0, 0, 1, 3, 11 - 1, 2013);
my $log_handler = Apache::LogFormat::Compiler->new();
my $req = req_to_psgi(GET "/");
my $res = [200,[],[q!OK!]];
print $log_handler->log_line($req,$res,0,2,$time);
print $log_handler->log_line($req,$res,0,2,$time+3599);
オフセットが
print $log_handler->log_line($req,$res,0,2,$time+3600);
変わった
__DATA__
127.0.0.1 - - [03/Nov/2013:01:00:00 -0400] "GET / HTTP/1.1" 200 0 "-" "-"
127.0.0.1 - - [03/Nov/2013:01:59:59 -0400] "GET / HTTP/1.1" 200 0 "-" "-"
127.0.0.1 - - [03/Nov/2013:01:00:00 -0500] "GET / HTTP/1.1" 200 0 "-" "-"
10. I'm trying to install
Apache::LogFormat::Compiler on
Android. This system has poor
support for locales, so the Perl is
usually compiled with -Ui_locale flag.
https://github.com/kazeburo/Apache-LogFormat-Compiler/pull/6
dex4er
Andoroidがsetlocaleをサポートしてない!
11. $ export LC_ALL=ja_JP.UTF-8
$ perl -MPOSIX=strftime
-E 'say strftime(q!%d/%b/%Y%T!,localtime());'
21/ 2月/2014:00:17:35
strftime(2) はlocaleによって出力が変わる
12. my $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
POSIX::setlocale(&POSIX::LC_ALL, 'C');
$time = POSIX::strftime(‘%d/%b/%Y:%T’,localtime());
POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
%{format}t がstrftime(2) を使っていて、
ALFCはstrftime(2)の前にsetlocale(LC_ALL,C)してた
13. |
\ __ /
_ (m) _ピコーン
|ミ|
/ `´ \
('A`)
ノヽノヽ
くく
そうだlocaleに影響を受けない
strftime(2)を作ろう
やめておけばよかった。。
15. $ export LC_ALL=ja_JP.UTF-8
$ perl -MPOSIX::strftime::Compiler=strftime
-E 'say strftime(q!%d/%b/%Y:%T!,localtime());'
21/Feb/2014:00:17:35
localeによって出力が変わらない! YATTA!!
16. Time::TZOffset
Show timezone offset strings like “+0900”
more portable than POSIX::strftime('%z') and fast
XSにてtm構造体のtm_gmtoffを取得するモジュール
gmtoffをサポートしていないOSでは
localtimeとgmtimeの差分を計算
18. use HTTP::Entity::Parser;
my $parser = HTTP::Entity::Parser->new;
$parser->register('application/x-www-form-urlencoded',
'HTTP::Entity::Parser::UrlEncoded');
$parser->register('multipart/form-data',
'HTTP::Entity::Parser::MultiPart');
$parser->register('application/json',
'HTTP::Entity::Parser::JSON');
sub app {
my $env = shift;
my ( $params, $uploads) = $parser->parse($env);
}
21. 'a=b&c=d'
'a=b;c=d'
'a=1&b=2;c=3'
'a==b&c==d'
'a=b& c=d'
'a=b; c=d'
'a=b; c =d'
'a=b;c= d '
'a=b&+c=d'
'a=b&+c+=d'
'a=b&c=+d+'
'a=b&%20c=d'
'a=b&%20c%20=d'
'a=b&c=%20d%20'
'a&c=d'
'a=b&=d'
'a=b&='
'&'
'='
''
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
=>
["a","b","c","d"]
["a","b","c","d"]
["a","1","b","2","c","3"]
["a","=b","c","=d"]
["a","b","c","d"]
["a","b","c","d"]
["a","b","c ","d"]
["a","b","c"," d "]
["a","b"," c","d"]
["a","b"," c ","d"]
["a","b","c"," d "]
["a","b"," c","d"]
["a","b"," c ","d"]
["a","b","c"," d "]
["a","","c","d"]
["a","b","","d"]
["a","b","",""]
["","","",""]
["",""]
Plack::RequestやHTTP::Bodyとの
[]
互換性を維持する
23. Benchmark: running parse_pp, parse_xs
for at least 3 CPU seconds...
parse_pp: 3 wallclock secs
( 3.00 usr + 0.00 sys = 3.00 CPU)
@ 27353.00/s (n=82059)
parse_xs: 3 wallclock secs
( 3.02 usr + 0.00 sys = 3.02 CPU)
@ 258802.32/s (n=781583)
Rate
parse_pp 27353/s
parse_xs 258802/s
parse_p
-846%
parseのベンチマークで
parse_xs
-89%
--
9.5倍高速
24. Benchmark: running build_pp, build_xs
for at least 3 CPU seconds...
build_pp: 4 wallclock secs
( 3.40 usr + 0.01 sys = 3.41 CPU)
@ 15048.68/s (n=51316)
build_xs: 4 wallclock secs
( 3.08 usr + 0.01 sys = 3.09 CPU)
@ 651364.08/s (n=2012715)
Rate build_pp build_xs
build_pp 15049/s
--98%
build_xs 651364/s
4228%
--
43倍高速
buildは
25. ## content length => 38 ##
Rate
http_body http_entity
http_body
35870/s
--41%
http_entity 60703/s
69%
-## content length => 177 ##
Rate
http_body http_entity
http_body
14355/s
--74%
http_entity 54371/s
279%
-## content length => 1997 ##
Rate
http_body http_entity
http_body
2054/s
--92%
http_entity 27049/s
1217%
--
WWW::Form::UrlEncoded::XSをいれた
HTTP::Entity::Parserのベンチマーク