SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
Perl5 meta programming 
YAPC::Asia 2014 
id:karupanerura
NOTICE 
Sorry. I don’t speak in English. 
Because, I’m not good at English. 
So, maybe the wrong english has been many included.
about me 
• Kenta Sato 
• id:karupanerura 
• github/twitter/etc.. 
• Perl/JavaScript/Java/elisp… 
• CPAN Author 
• PAUSE ID: KARUPA 
• Mobile Factory, Inc. 
• Lead Engineer 
• Social Application
Rock’n’roll engineer The Monzllis
Gotanda.pm 
• Conference 
• #1 6/11 (Wed) 
• #2 9/17 (Wed) <= come on !!! 
• hash tag (twitter) 
• #gotandapm 
• http://gotanda-pm.github.io/
CPAN 
• TOML.pm 
• TOML::Parser 
• Locale::Scope 
• Parallel::Async
My YAPC::Asia history. 
• 2011 LT 
• 2012 LT + Individual Sponsor 
• 2013 Talk 20min + Individual Sponsor 
• 2014 Talk 40min + Individual Sponsor <= now 
• + Volunteer Staff 
• 2015 ???
“I wanna be the best speaker.” 
– karupanerura
Please vote for me!!
Okay. Now starting.
What is meta programming?
World of meta programming 
• Make a program by program. 
• Example: 
• Define subroutine by program. 
• Define package by program. 
• Call specified subroutine by a variable. 
• Rewrite AST by program. (not talk about it today.) 
• Called as “PL_check hack”. (XS)
Which is implemented by meta programming? 
• constant / Exporter / parent 
• Class::Accessor / Class::MOP (Moose) etc… 
• Class::Method::Modifiers 
• Module::Spy / Test::MockObject / Test::Mock::Guard 
• Apache::LogFormat::Compiler / Template-Toolkit 
• and more…
Perl5 has meta programming culture.
What do we get by meta programing? 
• Support to DRY 
• Inner DSL 
• And, readable code. 
• Preprocessing 
• And, faster processing.
In other words, freedom
“With freedom comes responsibility.” 
–Eleanor Roosevelt
What do we get by meta programing? 
• Incomprehension code. 
• Dirty inner DSL 
• Not readable. 
• Long, and long, and long time preprocessing. 
• Yep, you get slower code.
Usage of meta programming.
Meta programming is difficult. 
• Very freedom. 
• Yes. We can do anything! 
• Tend to the complex. 
• Difficult to analyze code by human. 
• You can’t know the process until execute. 
• It’s extreme.
But, Why we want meta programming? 
• Want to apply monkey patch. 
• But, Don’t want to rewrite source code. 
• We want to create many method. 
• But, There are similar almost. 
• Want to generate methods automatically.
Vital point 
• Write test scripts!!!!!!!!!!!!!!!!!!!!!!! 
• Solve the problem in existing modules. 
• as much as possible. 
• Create module as simply. 
• Give up when you can not be simple. 
• Think about more fundamental problem.
How to implement 
by meta programming. 
in perl5
string eval 
• Preprocessing. 
• Create minimized code by template. 
(Apache::LogFormat::Compiler/Template-Toolkit) 
• Define package/subroutine by program. 
• Create something like an anonymous class. 
(Moo::Role/Mo[uo]se::Role/etc…) 
• And, more!!!
string eval 
• Execute code by string. 
• Very freedom. 
• Very useful. 
• Be careful perl code injection attack. 
• So, do *NOT* use it if not needed.
string eval 
DEMO
UNIVERSAL 
• Base package of all packages.
UNIVERSAL 
DEMO
symbol talbe 
• e.g.) %main:: 
• Haves almost definition information of package. 
• Haves all typeglobs. 
• We can modify it. 
• Define (package|subroutine) by program.
typeglob 
• “a typeglob to hold an entire symbol table 
entry.”(from perldoc perldata) 
• *foo haves $foo and @foo and %foo.
symbol table & typeglob 
DEMO
AUTOLOAD 
• Fallback of subroutine call.
AUTOLOAD 
DEMO
Package::Stash 
• Provides symbol table modifier and accessor.
Package::Stash 
DEMO
B.pm 
• Perl compiler backend. 
• Provides interface for access to inner data structure. 
• SV (PV|IV|NV|RV) / AV / HV / GV / CV / IO 
• e.g.) B::PV / B::IV / B::GV / B::CV / etc… 
• Provides many utility. (e.g. B::perlstring) 
• I'm not familiar. :0
B::svref_2object 
• Convert reference to B::* instance. 
• Access to inner information of object.
B::svref_2object 
DEMO
Class::Inspector 
• Provides to access information about a class and its 
structure 
• e.g.) methods, functions, etc…
Class::Inspector 
DEMO
Class::Method::Modifiers 
• Provides method modifiers. 
• e.g.) before, after, around, etc…
Class::Method::Modifiers 
DEMO
Mo[ou]se (Moo) 
• Provides meta object protocol. 
• Likes a Package::Stash. 
• e.g.) add_method, remove_method, etc… 
• Provides method modifiers. 
• e.g.) before, after, around, etc…
Moo 
DEMO
Summary 
• Get information from package. 
• Class::Inspector/Package::Stash/symbol table 
• and, meta object protocol (Mo[ou]se|Moo) 
• Define methods or packages. 
• Package::Stash/symbol table/meta object protocol. 
• A last resort 
• String eval.
Vital point AGAIN 
• Write test scripts!!!!!!!!!!!!!!!!!!!!!!! 
• Solve the problem in existing modules. 
• as much as possible. 
• Create module as simply. 
• Give up when you can not be simple. 
• Think about more fundamental problem.
Mobile Factory, Inc. 
• Using modern perl in many projects. 
• perl 5.18 + Carton + Amon2 + Starlet 
• perl 5.14 + Amon2 
• Free vegetable juices and other something drinks. 
• Everyone available dual display. (22inch x 2)
! 
Let’s work at Mobile Factory team!!
! 
Thank you for listening!!
Any questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Python introduction
Python introductionPython introduction
Python introduction
Roger Xia
 
Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010
Ted Dunning
 
Multilingual sites in plone
Multilingual sites in ploneMultilingual sites in plone
Multilingual sites in plone
Ramon Navarro
 
PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25
David Fetter
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
mametter
 

Was ist angesagt? (19)

ANTLR4 in depth
ANTLR4 in depthANTLR4 in depth
ANTLR4 in depth
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
 
Python intro and competitive programming
Python intro and competitive programmingPython intro and competitive programming
Python intro and competitive programming
 
Python introduction
Python introductionPython introduction
Python introduction
 
Vimeo and Open Source (SMPTE Forum 2015)
Vimeo and Open Source (SMPTE Forum 2015)Vimeo and Open Source (SMPTE Forum 2015)
Vimeo and Open Source (SMPTE Forum 2015)
 
Beginning Python
Beginning PythonBeginning Python
Beginning Python
 
Webinar: OpenNLP and Solr for Superior Relevance
Webinar: OpenNLP and Solr for Superior RelevanceWebinar: OpenNLP and Solr for Superior Relevance
Webinar: OpenNLP and Solr for Superior Relevance
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
 
Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010
 
Not Everything Is An Object
Not Everything Is An ObjectNot Everything Is An Object
Not Everything Is An Object
 
Alexander Kutsan "Where Unicorns Live or How To Write Good C++ Code"
Alexander Kutsan "Where Unicorns Live or How To Write Good C++ Code"Alexander Kutsan "Where Unicorns Live or How To Write Good C++ Code"
Alexander Kutsan "Where Unicorns Live or How To Write Good C++ Code"
 
Erlang: TL;DR
Erlang: TL;DRErlang: TL;DR
Erlang: TL;DR
 
F# for startups
F# for startupsF# for startups
F# for startups
 
Multilingual sites in plone
Multilingual sites in ploneMultilingual sites in plone
Multilingual sites in plone
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25PL/Parrot San Francisco Perl Mongers 2010/05/25
PL/Parrot San Francisco Perl Mongers 2010/05/25
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
Go for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B MeetupGo for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B Meetup
 

Andere mochten auch

若手Itエンジニア飲み会-LT
若手Itエンジニア飲み会-LT若手Itエンジニア飲み会-LT
若手Itエンジニア飲み会-LT
karupanerura
 
モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤
karupanerura
 
Adjoint Shape Optimization using OpenFOAM
Adjoint Shape Optimization using OpenFOAMAdjoint Shape Optimization using OpenFOAM
Adjoint Shape Optimization using OpenFOAM
Fumiya Nozaki
 
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみたオープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
Fumiya Nozaki
 
Spatial Interpolation Schemes in OpenFOAM
Spatial Interpolation Schemes in OpenFOAMSpatial Interpolation Schemes in OpenFOAM
Spatial Interpolation Schemes in OpenFOAM
Fumiya Nozaki
 
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
Fumiya Nozaki
 

Andere mochten auch (20)

Aniki has come
Aniki has comeAniki has come
Aniki has come
 
すいすいSwift
すいすいSwiftすいすいSwift
すいすいSwift
 
若手Itエンジニア飲み会-LT
若手Itエンジニア飲み会-LT若手Itエンジニア飲み会-LT
若手Itエンジニア飲み会-LT
 
Gotanda.pmの紹介
Gotanda.pmの紹介Gotanda.pmの紹介
Gotanda.pmの紹介
 
engineer-life
engineer-lifeengineer-life
engineer-life
 
Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.Aniki - The ORM as our great brother.
Aniki - The ORM as our great brother.
 
KOWAZA for mackerel
KOWAZA for mackerelKOWAZA for mackerel
KOWAZA for mackerel
 
Why we use mruby with Perl5?
Why we use mruby with Perl5?Why we use mruby with Perl5?
Why we use mruby with Perl5?
 
dwangocpp1-lt
dwangocpp1-ltdwangocpp1-lt
dwangocpp1-lt
 
The Crystal language *recently* update
The Crystal language *recently* updateThe Crystal language *recently* update
The Crystal language *recently* update
 
TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=TIme::Moment+Time::Strptime=
TIme::Moment+Time::Strptime=
 
Optimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaksOptimize perl5 code for perfomance freaks
Optimize perl5 code for perfomance freaks
 
【モバイルファクトリー】「いわて×駅メモ!」位置ゲームによる観光振興の可能性
【モバイルファクトリー】「いわて×駅メモ!」位置ゲームによる観光振興の可能性【モバイルファクトリー】「いわて×駅メモ!」位置ゲームによる観光振興の可能性
【モバイルファクトリー】「いわて×駅メモ!」位置ゲームによる観光振興の可能性
 
モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤モジュール開発におけるぼくの試行錯誤
モジュール開発におけるぼくの試行錯誤
 
Adjoint Shape Optimization using OpenFOAM
Adjoint Shape Optimization using OpenFOAMAdjoint Shape Optimization using OpenFOAM
Adjoint Shape Optimization using OpenFOAM
 
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみたオープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
オープンソースの CFD ソフトウェア SU2 のチュートリアルをやってみた
 
Spatial Interpolation Schemes in OpenFOAM
Spatial Interpolation Schemes in OpenFOAMSpatial Interpolation Schemes in OpenFOAM
Spatial Interpolation Schemes in OpenFOAM
 
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
OpenFOAM -空間の離散化と係数行列の取り扱い(Spatial Discretization and Coefficient Matrix)-
 
OpenFOAMの壁関数
OpenFOAMの壁関数OpenFOAMの壁関数
OpenFOAMの壁関数
 
Boundary Conditions in OpenFOAM
Boundary Conditions in OpenFOAMBoundary Conditions in OpenFOAM
Boundary Conditions in OpenFOAM
 

Ähnlich wie Perl5 meta programming

これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
goccy
 
Bridging the Gap - Laracon 2013
Bridging the Gap - Laracon 2013Bridging the Gap - Laracon 2013
Bridging the Gap - Laracon 2013
Ben Corlett
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
Mike Harris
 

Ähnlich wie Perl5 meta programming (20)

Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Bridging the Gap - Laracon 2013
Bridging the Gap - Laracon 2013Bridging the Gap - Laracon 2013
Bridging the Gap - Laracon 2013
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
 
Reproducibility and automation of machine learning process
Reproducibility and automation of machine learning processReproducibility and automation of machine learning process
Reproducibility and automation of machine learning process
 
Intro to Python for C# Developers
Intro to Python for C# DevelopersIntro to Python for C# Developers
Intro to Python for C# Developers
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Tuples, Dicts and Exception Handling
Tuples, Dicts and Exception HandlingTuples, Dicts and Exception Handling
Tuples, Dicts and Exception Handling
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 

Mehr von karupanerura

mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lock
karupanerura
 
Yapc asia-2012-lt-thon
Yapc asia-2012-lt-thonYapc asia-2012-lt-thon
Yapc asia-2012-lt-thon
karupanerura
 
ぼくがかんがえたさいきょうのMvc
ぼくがかんがえたさいきょうのMvcぼくがかんがえたさいきょうのMvc
ぼくがかんがえたさいきょうのMvc
karupanerura
 
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
karupanerura
 

Mehr von karupanerura (17)

Perl5 VS JSON
Perl5 VS JSONPerl5 VS JSON
Perl5 VS JSON
 
コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良く
 
The plan of Aniki 2.0
The plan of Aniki 2.0The plan of Aniki 2.0
The plan of Aniki 2.0
 
Aniki::Internal
Aniki::InternalAniki::Internal
Aniki::Internal
 
DateTimeX::Moment
DateTimeX::MomentDateTimeX::Moment
DateTimeX::Moment
 
Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術Technology for reduce of mistakes - うっかりをなくす技術
Technology for reduce of mistakes - うっかりをなくす技術
 
router-simple.cr
router-simple.crrouter-simple.cr
router-simple.cr
 
はかたの塩
はかたの塩はかたの塩
はかたの塩
 
Perlにおけるclass実装パターン
Perlにおけるclass実装パターンPerlにおけるclass実装パターン
Perlにおけるclass実装パターン
 
mysqlcasual6-next-key-lock
mysqlcasual6-next-key-lockmysqlcasual6-next-key-lock
mysqlcasual6-next-key-lock
 
Hachioji.pm #40
Hachioji.pm #40Hachioji.pm #40
Hachioji.pm #40
 
Hachioji.pm #39
Hachioji.pm #39Hachioji.pm #39
Hachioji.pm #39
 
perl5の日付時刻処理とか
perl5の日付時刻処理とかperl5の日付時刻処理とか
perl5の日付時刻処理とか
 
Yapc asia-2012-lt-thon
Yapc asia-2012-lt-thonYapc asia-2012-lt-thon
Yapc asia-2012-lt-thon
 
ぼくがかんがえたさいきょうのMvc
ぼくがかんがえたさいきょうのMvcぼくがかんがえたさいきょうのMvc
ぼくがかんがえたさいきょうのMvc
 
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
Perl RDBMS Programming(DBI/DBIx::Sunnyのはなし)
 
Teng tips
Teng tipsTeng tips
Teng tips
 

Kürzlich hochgeladen

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
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 

Perl5 meta programming

  • 1. Perl5 meta programming YAPC::Asia 2014 id:karupanerura
  • 2. NOTICE Sorry. I don’t speak in English. Because, I’m not good at English. So, maybe the wrong english has been many included.
  • 3. about me • Kenta Sato • id:karupanerura • github/twitter/etc.. • Perl/JavaScript/Java/elisp… • CPAN Author • PAUSE ID: KARUPA • Mobile Factory, Inc. • Lead Engineer • Social Application
  • 5. Gotanda.pm • Conference • #1 6/11 (Wed) • #2 9/17 (Wed) <= come on !!! • hash tag (twitter) • #gotandapm • http://gotanda-pm.github.io/
  • 6. CPAN • TOML.pm • TOML::Parser • Locale::Scope • Parallel::Async
  • 7. My YAPC::Asia history. • 2011 LT • 2012 LT + Individual Sponsor • 2013 Talk 20min + Individual Sponsor • 2014 Talk 40min + Individual Sponsor <= now • + Volunteer Staff • 2015 ???
  • 8. “I wanna be the best speaker.” – karupanerura
  • 11. What is meta programming?
  • 12. World of meta programming • Make a program by program. • Example: • Define subroutine by program. • Define package by program. • Call specified subroutine by a variable. • Rewrite AST by program. (not talk about it today.) • Called as “PL_check hack”. (XS)
  • 13. Which is implemented by meta programming? • constant / Exporter / parent • Class::Accessor / Class::MOP (Moose) etc… • Class::Method::Modifiers • Module::Spy / Test::MockObject / Test::Mock::Guard • Apache::LogFormat::Compiler / Template-Toolkit • and more…
  • 14. Perl5 has meta programming culture.
  • 15.
  • 16. What do we get by meta programing? • Support to DRY • Inner DSL • And, readable code. • Preprocessing • And, faster processing.
  • 17. In other words, freedom
  • 18. “With freedom comes responsibility.” –Eleanor Roosevelt
  • 19. What do we get by meta programing? • Incomprehension code. • Dirty inner DSL • Not readable. • Long, and long, and long time preprocessing. • Yep, you get slower code.
  • 20. Usage of meta programming.
  • 21. Meta programming is difficult. • Very freedom. • Yes. We can do anything! • Tend to the complex. • Difficult to analyze code by human. • You can’t know the process until execute. • It’s extreme.
  • 22. But, Why we want meta programming? • Want to apply monkey patch. • But, Don’t want to rewrite source code. • We want to create many method. • But, There are similar almost. • Want to generate methods automatically.
  • 23. Vital point • Write test scripts!!!!!!!!!!!!!!!!!!!!!!! • Solve the problem in existing modules. • as much as possible. • Create module as simply. • Give up when you can not be simple. • Think about more fundamental problem.
  • 24. How to implement by meta programming. in perl5
  • 25. string eval • Preprocessing. • Create minimized code by template. (Apache::LogFormat::Compiler/Template-Toolkit) • Define package/subroutine by program. • Create something like an anonymous class. (Moo::Role/Mo[uo]se::Role/etc…) • And, more!!!
  • 26. string eval • Execute code by string. • Very freedom. • Very useful. • Be careful perl code injection attack. • So, do *NOT* use it if not needed.
  • 28. UNIVERSAL • Base package of all packages.
  • 30. symbol talbe • e.g.) %main:: • Haves almost definition information of package. • Haves all typeglobs. • We can modify it. • Define (package|subroutine) by program.
  • 31. typeglob • “a typeglob to hold an entire symbol table entry.”(from perldoc perldata) • *foo haves $foo and @foo and %foo.
  • 32. symbol table & typeglob DEMO
  • 33. AUTOLOAD • Fallback of subroutine call.
  • 35. Package::Stash • Provides symbol table modifier and accessor.
  • 37. B.pm • Perl compiler backend. • Provides interface for access to inner data structure. • SV (PV|IV|NV|RV) / AV / HV / GV / CV / IO • e.g.) B::PV / B::IV / B::GV / B::CV / etc… • Provides many utility. (e.g. B::perlstring) • I'm not familiar. :0
  • 38. B::svref_2object • Convert reference to B::* instance. • Access to inner information of object.
  • 40. Class::Inspector • Provides to access information about a class and its structure • e.g.) methods, functions, etc…
  • 42. Class::Method::Modifiers • Provides method modifiers. • e.g.) before, after, around, etc…
  • 44. Mo[ou]se (Moo) • Provides meta object protocol. • Likes a Package::Stash. • e.g.) add_method, remove_method, etc… • Provides method modifiers. • e.g.) before, after, around, etc…
  • 46. Summary • Get information from package. • Class::Inspector/Package::Stash/symbol table • and, meta object protocol (Mo[ou]se|Moo) • Define methods or packages. • Package::Stash/symbol table/meta object protocol. • A last resort • String eval.
  • 47. Vital point AGAIN • Write test scripts!!!!!!!!!!!!!!!!!!!!!!! • Solve the problem in existing modules. • as much as possible. • Create module as simply. • Give up when you can not be simple. • Think about more fundamental problem.
  • 48. Mobile Factory, Inc. • Using modern perl in many projects. • perl 5.18 + Carton + Amon2 + Starlet • perl 5.14 + Amon2 • Free vegetable juices and other something drinks. • Everyone available dual display. (22inch x 2)
  • 49. ! Let’s work at Mobile Factory team!!
  • 50. ! Thank you for listening!!