SlideShare a Scribd company logo
1 of 25
Download to read offline
OGATA Tetsuji (@xtetsuji)
2017/01/19 Gaiax
https://flic.kr/p/77EHJk
• OGATA Tetsuji a.k.a. @xtetsuji
• http://post.tetsuji.jp/
• RND INFR
• Perl 🐫/ Debian 🌀 / Postfix MTA 📩 / Mathematics 🔢 /
Classical Music 🎵 / Cafe ☕ / Route Bus 🚌
•
•
•
•
•
https://flic.kr/p/77EHJk
•
•
• eval
- Perl
sub AUTOLOAD {
my ( $self, $args ) = @_;
our $AUTOLOAD;
my $class = ref $self; # PROJECT::Model::FUNC
my $method = $AUTOLOAD; # PROJECT::Model::FUNC::hoge
$method =~ s/$class:://;
$class =~ s/^PROJECT::Model:://;
return $self->mysql->{ $class }->$method( $args );
}
• Perl
AUTOLOAD
•
$AUTOLOAD
•
AUTOLOAD
•
•
•
•
AUTOLOAD
• AUTOLOAD
• CGI
• CGI.pm
### From CGI package version 2.99
sub AUTOLOAD {
print STDERR "CGI::AUTOLOAD for $AUTOLOADn" if $CGI::AUTOLOAD_DEBUG;
my $func = &_compile;
goto &$func;
}
• _compile
• LL
• eval
sub _compile {
my($func) = $AUTOLOAD;
my($pack,$func_name);
{
local($1,$2); # this fixes an obscure variable suicide problem.
$func=~/(.+)::([^:]+)$/;
($pack,$func_name) = ($1,$2);
$pack=~s/::SUPER$//; # fix another obscure problem
$pack = ${"$pack::AutoloadClass"} || $CGI::DefaultClass
unless defined(${"$pack::AUTOLOADED_ROUTINES"});
my($sub) = %{"$pack::SUBS"};
unless (%$sub) {
my($auto) = ${"$pack::AUTOLOADED_ROUTINES"};
eval "package $pack; $$auto";
croak("$AUTOLOAD: $@") if $@;
$$auto = ''; # Free the unneeded storage (but don't undef it!!!)
}
my($code) = $sub->{$func_name};
$code = "sub $AUTOLOAD { }" if (!$code and $func_name eq 'DESTROY');
if (!$code) {
(my $base = $func_name) =~ s/^(start_|end_)//i;
if ($EXPORT{':any'} ||
$EXPORT{'-any'} ||
$EXPORT{$base} ||
(%EXPORT_OK || grep(++$EXPORT_OK{$_},&expand_tags(':html')))
&& $EXPORT_OK{$base}) {
$code = $CGI::DefaultClass->_make_tag_func($func_name);
}
}
croak("Undefined subroutine $AUTOLOADn") unless $code;
eval "package $pack; $code";
if ($@) {
$@ =~ s/ at .*n//;
croak("$AUTOLOAD: $@");
}
}
CORE::delete($sub->{$func_name}); #free storage
return "$pack::$func_name";
}
• AUTOLOAD
$AUTLOAD $code
• $code eval
• AUTOLOAD
• 2004 CGI.pm 2.99
•
• CGI.pm 4.35 AUTOLOAD
• fork CPU CGI
• Q:
• A:
Apache::LogFormat::Compiler
• new Apache
• "custom", "combine" %*
• log_line PSGI
• log_line
sub new {
my $class = shift;
my $fmt = shift || "combined";
$fmt = $formats{$fmt} if exists $formats{$fmt};
my %opts = @_;
my ($code_ref, $code) = compile($fmt, $opts{block_handlers} || {},
$opts{char_handlers} || {});
bless [$code_ref, $code], $class;
}
sub log_line {
my $self = shift;
$self->[0]->(@_) . "n";
}
sub compile {
my $fmt = shift;
my $extra_block_handlers = shift;
my $extra_char_handlers = shift;
$fmt =~ s/!/!/g;
$fmt =~ s!
(?:
%{(.+?)}([a-zA-Z]) |
%(?:[<>])?([a-zA-Z%])
)
! $1 ? $block_handler->($1, $2, $extra_block_handlers) : $char_handler->($3, $extra_char_handlers) !egx;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $c = {};
$fmt = q~sub {
$_[TIME] = time() if ! defined $_[TIME];
my @lt = localtime($_[TIME]);
if ( ! exists $c->{tz_cache} || ! exists $c->{isdst_cache} || $lt[8] != $c->{isdst_cache} ) {
$c->{tz_cache} = POSIX::strftime::Compiler::strftime('%z',@lt);
$c->{isdst_cache} = $lt[8];
}
my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3], $abbr[$lt[4]], $lt[5]+1900,
$lt[2], $lt[1], $lt[0], $c->{tz_cache};
q!~ . $fmt . q~!
}~;
my $code_ref = eval $fmt; ## no critic
die $@ . "n===n" . $fmt if $@;
wantarray ? ($code_ref, $fmt) : $code_ref;
}
•
• log_line
eval
•
•
•
• Perl eval
• eval try
コードの動的生成のお話

More Related Content

What's hot

YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYusuke Wada
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON APIpodsframework
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravelRazvan Raducanu, PhD
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちRyo Miyake
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門Yusuke Wada
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Arc & Codementor
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Puppet
 
Manifests of Future Past
Manifests of Future PastManifests of Future Past
Manifests of Future PastPuppet
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax pluginsInbal Geffen
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tinywaniji
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 

What's hot (20)

YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON API
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
 
Tax management-system
Tax management-systemTax management-system
Tax management-system
 
Modern php
Modern phpModern php
Modern php
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Feeds drupal cafe
Feeds drupal cafeFeeds drupal cafe
Feeds drupal cafe
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
Manifests of Future Past
Manifests of Future PastManifests of Future Past
Manifests of Future Past
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tiny
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 

Viewers also liked

最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話鉄次 尾形
 
再帰、漸化式、差分方程式とアルゴリズム Gx#20
再帰、漸化式、差分方程式とアルゴリズム   Gx#20再帰、漸化式、差分方程式とアルゴリズム   Gx#20
再帰、漸化式、差分方程式とアルゴリズム Gx#20鉄次 尾形
 
4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ鉄次 尾形
 
穏やかにファイルを削除する続き
穏やかにファイルを削除する続き穏やかにファイルを削除する続き
穏やかにファイルを削除する続き鉄次 尾形
 
超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual鉄次 尾形
 
三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか鉄次 尾形
 
日本全国ぶらりPerl旅
日本全国ぶらりPerl旅日本全国ぶらりPerl旅
日本全国ぶらりPerl旅鉄次 尾形
 
Perlで生きる10年
Perlで生きる10年Perlで生きる10年
Perlで生きる10年鉄次 尾形
 
穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する鉄次 尾形
 
Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜鉄次 尾形
 

Viewers also liked (10)

最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話最近のメールまわりのお仕事のお話
最近のメールまわりのお仕事のお話
 
再帰、漸化式、差分方程式とアルゴリズム Gx#20
再帰、漸化式、差分方程式とアルゴリズム   Gx#20再帰、漸化式、差分方程式とアルゴリズム   Gx#20
再帰、漸化式、差分方程式とアルゴリズム Gx#20
 
4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ4月16日だからFoursquare 位置情報とライフログ
4月16日だからFoursquare 位置情報とライフログ
 
穏やかにファイルを削除する続き
穏やかにファイルを削除する続き穏やかにファイルを削除する続き
穏やかにファイルを削除する続き
 
超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual超小規模環境のMySQL #mysqlcasual
超小規模環境のMySQL #mysqlcasual
 
三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか三角関数の加法定理はなぜ難しいのか
三角関数の加法定理はなぜ難しいのか
 
日本全国ぶらりPerl旅
日本全国ぶらりPerl旅日本全国ぶらりPerl旅
日本全国ぶらりPerl旅
 
Perlで生きる10年
Perlで生きる10年Perlで生きる10年
Perlで生きる10年
 
穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する
 
Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜Perl ウェブ開発の中世〜CGI と Plack の間〜
Perl ウェブ開発の中世〜CGI と Plack の間〜
 

Similar to コードの動的生成のお話

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopJeroen Keppens
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To MocoNaoya Ito
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterCodeIgniter Conference
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたmemememomo
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in phpWade Womersley
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3Jeremy Coates
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
Power Theming
Power ThemingPower Theming
Power Themingdrkdn
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Designunodelostrece
 

Similar to コードの動的生成のお話 (20)

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Bioinformatics p5-bioperlv2014
Bioinformatics p5-bioperlv2014Bioinformatics p5-bioperlv2014
Bioinformatics p5-bioperlv2014
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in php
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Power Theming
Power ThemingPower Theming
Power Theming
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 

More from 鉄次 尾形

Perl入学式 2018年度の報告
Perl入学式 2018年度の報告Perl入学式 2018年度の報告
Perl入学式 2018年度の報告鉄次 尾形
 
【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア鉄次 尾形
 
俺のこだわりデスクのその後
俺のこだわりデスクのその後俺のこだわりデスクのその後
俺のこだわりデスクのその後鉄次 尾形
 
WordPress 運用を支える Perl
WordPress 運用を支える PerlWordPress 運用を支える Perl
WordPress 運用を支える Perl鉄次 尾形
 
障害対応とその防止策
障害対応とその防止策障害対応とその防止策
障害対応とその防止策鉄次 尾形
 
働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール鉄次 尾形
 
mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論鉄次 尾形
 
東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015鉄次 尾形
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式鉄次 尾形
 
ライフログ、時系列メモ
ライフログ、時系列メモライフログ、時系列メモ
ライフログ、時系列メモ鉄次 尾形
 
今に伝えるメールの技術 #yapcasia #yapcasiareject
今に伝えるメールの技術 #yapcasia #yapcasiareject今に伝えるメールの技術 #yapcasia #yapcasiareject
今に伝えるメールの技術 #yapcasia #yapcasiareject鉄次 尾形
 
マルチタスクって奥が深い #mishimapm
マルチタスクって奥が深い #mishimapmマルチタスクって奥が深い #mishimapm
マルチタスクって奥が深い #mishimapm鉄次 尾形
 
2014年には役に立たないセッションの昔話 #hachiojipm
2014年には役に立たないセッションの昔話 #hachiojipm2014年には役に立たないセッションの昔話 #hachiojipm
2014年には役に立たないセッションの昔話 #hachiojipm鉄次 尾形
 
そのsleep、ちょっと待った! #perlbeginners
そのsleep、ちょっと待った! #perlbeginnersそのsleep、ちょっと待った! #perlbeginners
そのsleep、ちょっと待った! #perlbeginners鉄次 尾形
 
環境が変わって最近知ったもの #hachiojipm
環境が変わって最近知ったもの #hachiojipm環境が変わって最近知ったもの #hachiojipm
環境が変わって最近知ったもの #hachiojipm鉄次 尾形
 
これからPerlを使っていくみなさんへ #Perl入学式
これからPerlを使っていくみなさんへ #Perl入学式これからPerlを使っていくみなさんへ #Perl入学式
これからPerlを使っていくみなさんへ #Perl入学式鉄次 尾形
 
エディタ遍歴2014 #hachiojipm
エディタ遍歴2014 #hachiojipmエディタ遍歴2014 #hachiojipm
エディタ遍歴2014 #hachiojipm鉄次 尾形
 
今年作ったもの2013 #hokkaidopm
今年作ったもの2013 #hokkaidopm今年作ったもの2013 #hokkaidopm
今年作ったもの2013 #hokkaidopm鉄次 尾形
 
プロセスの永続化でコスト削減 #perlbeginners
プロセスの永続化でコスト削減 #perlbeginnersプロセスの永続化でコスト削減 #perlbeginners
プロセスの永続化でコスト削減 #perlbeginners鉄次 尾形
 

More from 鉄次 尾形 (20)

Perl入学式 2018年度の報告
Perl入学式 2018年度の報告Perl入学式 2018年度の報告
Perl入学式 2018年度の報告
 
【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア【公開版】AWS基礎 for 新卒エンジニア
【公開版】AWS基礎 for 新卒エンジニア
 
俺のこだわりデスクのその後
俺のこだわりデスクのその後俺のこだわりデスクのその後
俺のこだわりデスクのその後
 
Hokkaido.pmと7年
Hokkaido.pmと7年Hokkaido.pmと7年
Hokkaido.pmと7年
 
WordPress 運用を支える Perl
WordPress 運用を支える PerlWordPress 運用を支える Perl
WordPress 運用を支える Perl
 
障害対応とその防止策
障害対応とその防止策障害対応とその防止策
障害対応とその防止策
 
働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール働きやすい社内を目指す!二酸化炭素計測ツール
働きやすい社内を目指す!二酸化炭素計測ツール
 
mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論mod_perlプログラマーがYAPCで語るレガシー開発論
mod_perlプログラマーがYAPCで語るレガシー開発論
 
東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015東京近郊のPerlコミュニティのご紹介 #lcs2015
東京近郊のPerlコミュニティのご紹介 #lcs2015
 
設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式設定ファイルに使われそうなデータ形式
設定ファイルに使われそうなデータ形式
 
ライフログ、時系列メモ
ライフログ、時系列メモライフログ、時系列メモ
ライフログ、時系列メモ
 
今に伝えるメールの技術 #yapcasia #yapcasiareject
今に伝えるメールの技術 #yapcasia #yapcasiareject今に伝えるメールの技術 #yapcasia #yapcasiareject
今に伝えるメールの技術 #yapcasia #yapcasiareject
 
マルチタスクって奥が深い #mishimapm
マルチタスクって奥が深い #mishimapmマルチタスクって奥が深い #mishimapm
マルチタスクって奥が深い #mishimapm
 
2014年には役に立たないセッションの昔話 #hachiojipm
2014年には役に立たないセッションの昔話 #hachiojipm2014年には役に立たないセッションの昔話 #hachiojipm
2014年には役に立たないセッションの昔話 #hachiojipm
 
そのsleep、ちょっと待った! #perlbeginners
そのsleep、ちょっと待った! #perlbeginnersそのsleep、ちょっと待った! #perlbeginners
そのsleep、ちょっと待った! #perlbeginners
 
環境が変わって最近知ったもの #hachiojipm
環境が変わって最近知ったもの #hachiojipm環境が変わって最近知ったもの #hachiojipm
環境が変わって最近知ったもの #hachiojipm
 
これからPerlを使っていくみなさんへ #Perl入学式
これからPerlを使っていくみなさんへ #Perl入学式これからPerlを使っていくみなさんへ #Perl入学式
これからPerlを使っていくみなさんへ #Perl入学式
 
エディタ遍歴2014 #hachiojipm
エディタ遍歴2014 #hachiojipmエディタ遍歴2014 #hachiojipm
エディタ遍歴2014 #hachiojipm
 
今年作ったもの2013 #hokkaidopm
今年作ったもの2013 #hokkaidopm今年作ったもの2013 #hokkaidopm
今年作ったもの2013 #hokkaidopm
 
プロセスの永続化でコスト削減 #perlbeginners
プロセスの永続化でコスト削減 #perlbeginnersプロセスの永続化でコスト削減 #perlbeginners
プロセスの永続化でコスト削減 #perlbeginners
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

コードの動的生成のお話

  • 1. OGATA Tetsuji (@xtetsuji) 2017/01/19 Gaiax https://flic.kr/p/77EHJk
  • 2. • OGATA Tetsuji a.k.a. @xtetsuji • http://post.tetsuji.jp/ • RND INFR • Perl 🐫/ Debian 🌀 / Postfix MTA 📩 / Mathematics 🔢 / Classical Music 🎵 / Cafe ☕ / Route Bus 🚌
  • 7. sub AUTOLOAD { my ( $self, $args ) = @_; our $AUTOLOAD; my $class = ref $self; # PROJECT::Model::FUNC my $method = $AUTOLOAD; # PROJECT::Model::FUNC::hoge $method =~ s/$class:://; $class =~ s/^PROJECT::Model:://; return $self->mysql->{ $class }->$method( $args ); }
  • 11. ### From CGI package version 2.99 sub AUTOLOAD { print STDERR "CGI::AUTOLOAD for $AUTOLOADn" if $CGI::AUTOLOAD_DEBUG; my $func = &_compile; goto &$func; }
  • 13. sub _compile { my($func) = $AUTOLOAD; my($pack,$func_name); { local($1,$2); # this fixes an obscure variable suicide problem. $func=~/(.+)::([^:]+)$/; ($pack,$func_name) = ($1,$2); $pack=~s/::SUPER$//; # fix another obscure problem $pack = ${"$pack::AutoloadClass"} || $CGI::DefaultClass unless defined(${"$pack::AUTOLOADED_ROUTINES"}); my($sub) = %{"$pack::SUBS"}; unless (%$sub) { my($auto) = ${"$pack::AUTOLOADED_ROUTINES"}; eval "package $pack; $$auto"; croak("$AUTOLOAD: $@") if $@; $$auto = ''; # Free the unneeded storage (but don't undef it!!!) } my($code) = $sub->{$func_name}; $code = "sub $AUTOLOAD { }" if (!$code and $func_name eq 'DESTROY'); if (!$code) { (my $base = $func_name) =~ s/^(start_|end_)//i; if ($EXPORT{':any'} || $EXPORT{'-any'} || $EXPORT{$base} || (%EXPORT_OK || grep(++$EXPORT_OK{$_},&expand_tags(':html'))) && $EXPORT_OK{$base}) { $code = $CGI::DefaultClass->_make_tag_func($func_name); } } croak("Undefined subroutine $AUTOLOADn") unless $code; eval "package $pack; $code"; if ($@) { $@ =~ s/ at .*n//; croak("$AUTOLOAD: $@"); } } CORE::delete($sub->{$func_name}); #free storage return "$pack::$func_name"; }
  • 14. • AUTOLOAD $AUTLOAD $code • $code eval • AUTOLOAD
  • 15. • 2004 CGI.pm 2.99 • • CGI.pm 4.35 AUTOLOAD • fork CPU CGI
  • 19.
  • 20. • new Apache • "custom", "combine" %* • log_line PSGI • log_line
  • 21. sub new { my $class = shift; my $fmt = shift || "combined"; $fmt = $formats{$fmt} if exists $formats{$fmt}; my %opts = @_; my ($code_ref, $code) = compile($fmt, $opts{block_handlers} || {}, $opts{char_handlers} || {}); bless [$code_ref, $code], $class; } sub log_line { my $self = shift; $self->[0]->(@_) . "n"; }
  • 22. sub compile { my $fmt = shift; my $extra_block_handlers = shift; my $extra_char_handlers = shift; $fmt =~ s/!/!/g; $fmt =~ s! (?: %{(.+?)}([a-zA-Z]) | %(?:[<>])?([a-zA-Z%]) ) ! $1 ? $block_handler->($1, $2, $extra_block_handlers) : $char_handler->($3, $extra_char_handlers) !egx; my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my $c = {}; $fmt = q~sub { $_[TIME] = time() if ! defined $_[TIME]; my @lt = localtime($_[TIME]); if ( ! exists $c->{tz_cache} || ! exists $c->{isdst_cache} || $lt[8] != $c->{isdst_cache} ) { $c->{tz_cache} = POSIX::strftime::Compiler::strftime('%z',@lt); $c->{isdst_cache} = $lt[8]; } my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3], $abbr[$lt[4]], $lt[5]+1900, $lt[2], $lt[1], $lt[0], $c->{tz_cache}; q!~ . $fmt . q~! }~; my $code_ref = eval $fmt; ## no critic die $@ . "n===n" . $fmt if $@; wantarray ? ($code_ref, $fmt) : $code_ref; }