SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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
コードの動的生成のお話

Weitere ähnliche Inhalte

Was ist angesagt?

YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 
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 Applications
elliando dias
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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 の間〜
 

Ähnlich wie コードの動的生成のお話

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 
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
Jeroen Keppens
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
Naoya Ito
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
CodeIgniter 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 php
Wade Womersley
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Power Theming
Power ThemingPower Theming
Power Theming
drkdn
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
unodelostrece
 

Ähnlich wie コードの動的生成のお話 (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
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Power Theming
Power ThemingPower Theming
Power Theming
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 

Mehr von 鉄次 尾形

Mehr von 鉄次 尾形 (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
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

コードの動的生成のお話

  • 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; }