SlideShare ist ein Scribd-Unternehmen logo
1 von 92
Downloaden Sie, um offline zu lesen
Static Code Analysis
for Perl
@moznion
Taiki Kawakami
a.k.a @moznion
Sever side engineer
(Java and Perl)
Author of
- Perl::Lint
- go-setlock
Taiki Kawakami
a.k.a @moznion
Sever side engineer
(Java and Perl)
Author of
- Perl::Lint
- go-setlock
Taiki Kawakami
a.k.a @moznion
Sever side engineer
(Java and Perl)
Author of
- Perl::Lint
- go-setlock
Fundamental of
Static Analysis
Static Analysis
A method of analysis
source code WITHOUT
execution
Static Analysis
Example of advantages:
- Easy to detect
- unused vars
- irregular coding styles
- Analyze dependencies
between modules/classes
Static Analysis
Example of advantages:
- Easy to detect
- unused vars
- irregular coding styles
- Analyze dependencies
between modules/classes
BORING!
Static Analysis
Example of advantages:
- Easy to detect
- unused vars
- irregular coding styles
- Analyze dependencies
between modules/classes
Difficult…
Let's Exercise
This code has 5 traps
This code has 5 traps
This code has 5 traps
This code has 5 traps
This code has 5 traps
This code has 5 traps
It was fun?
This is ridiculous
code ceview
Probably
human overlooks
We should focus on
advanced topic
on code review
How?
It is necessary
clean code
Destroy these
Be maintainable
code!
Make computer
analyze them!
How to make
static analyzer?
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
PPI::Tokenizer
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
PPI::Document
Provides
PDOM
Structure
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
“Analyze” phase
checks code with
using AST and tokens
in accordance with
rules
Method of some
languages are
different;
they look byte code
(e.g. Java:findbugs)
Perl::Critic
Perl::Critic is the
great tool!
Perl::Critic checks
the code conform
to PBP style or not
Perl::Critic uses
PPI as a Lexer
and Parser
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
PPI
Perl::Lint
Perl::Lint is a
yet another static
analyser for perl
This project
supported by TPF
Perl::Critic is enough.
Why Perl::Lint?
I want to make it
faster!!!
Mechanism of
Perl::Lint
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Regex
Compiler::Lexer
Perl::Lint::Policy
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Regex
Compiler::Lexer
Perl::Lint::Policy
Pre-Processing
## no lint
## no lint
To retrieve this
Find where (what line) is
“## no lint” by regex
Find where (what line) is
“## no lint” by regex
And compare between
line number of “## no lint”
and violation’s one,
if match them, ignore form result!
Compiler::Lexer can retrieve
comments by verbose mode,
but it makes slower about 4 times😢
So using regex
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Regex
Compiler::Lexer
Perl::Lint::Policy
Tokenize source code
by Compiler::Lexer
Compiler::Lexer made of C++
Really fast!
Stable (nowadays)
But…
Perl-5.22………………
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Regex
Compiler::Lexer
Perl::Lint::Policy
Compiler::Parser exists,
but that doesn’t work as expected
Pre-Process
Lexical Analyze
Syntactic Analyze
Source code (String)
Result
Analyze
Regex
Compiler::Lexer
Perl::Lint::Policy
Read token list sequentially
and evaluate them.
Each policies are responsible
for those.
Like this
Like this
Like this…
And it is necessary to analyze
contents of regex (m/here!/)
Using Regexp::Lexer
This is a module to tokenize regex
Example;
Each policies are independent,
so easy to write new policy
(You can write your own policy)
Easy and Simple:
Scan tokens and write
validation processing according to
scanned token sequentially
Perl::Lint has filter system
Perl::Lint executes all of the policies
by default.
Write a black list to ignore
any policy.
Current Status
Almost policies of Perl::Critic
are available on Perl::Lint
現状のステータス
Documentation is lacked…
Application
Test::Perl::Lint
Testing module like a
Test::Perl::Critic
Perl::Lint::Git
Connect git and Perl::Lint to blame the right people for
violations.Connect git and Perl::Lint to blame
the right people for violations.
Future works
I should have written a parser…
Compiler::Lexer::PP (?)
Enhance documentation
Bug fix
Support new perl notations
Support code climate
CHEATING:
Run each policies with
pre-fork model
Any Q?
(If I can answer…)

Weitere ähnliche Inhalte

Was ist angesagt?

ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caring
sporst
 
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? (20)

Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caring
 
GooglePropsal
GooglePropsalGooglePropsal
GooglePropsal
 
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
ITB2019 Real World Scenarios for Modern CFML - Nolan ErckITB2019 Real World Scenarios for Modern CFML - Nolan Erck
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3Type Profiler: Ambitious Type Inference for Ruby 3
Type Profiler: Ambitious Type Inference for Ruby 3
 
Asynchronous I/O in Python 3
Asynchronous I/O in Python 3Asynchronous I/O in Python 3
Asynchronous I/O in Python 3
 
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
 
Implementation of TypeGraphQL with Apollo Server
Implementation of TypeGraphQL with Apollo ServerImplementation of TypeGraphQL with Apollo Server
Implementation of TypeGraphQL with Apollo Server
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLR
 
Code samples that actually compile - Clare Macrae
Code samples that actually compile - Clare MacraeCode samples that actually compile - Clare Macrae
Code samples that actually compile - Clare Macrae
 
Python master class part 1
Python master class part 1Python master class part 1
Python master class part 1
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Erlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent WorldErlang - Concurrent Language for Concurrent World
Erlang - Concurrent Language for Concurrent World
 
F# for Scala developers
F# for Scala developersF# for Scala developers
F# for Scala developers
 
From V8 to Modern Compilers
From V8 to Modern CompilersFrom V8 to Modern Compilers
From V8 to Modern Compilers
 
Kotlin L → ∞
Kotlin L → ∞Kotlin L → ∞
Kotlin L → ∞
 

Andere mochten auch (6)

Namba.pm #0
Namba.pm #0Namba.pm #0
Namba.pm #0
 
Redux: server side rendering and hot code reload for single-page applications
Redux: server side rendering and hot code reload for single-page applicationsRedux: server side rendering and hot code reload for single-page applications
Redux: server side rendering and hot code reload for single-page applications
 
Yet Another Perl Cooking
Yet Another Perl CookingYet Another Perl Cooking
Yet Another Perl Cooking
 
Talking About Japanese Area Code of Phone
Talking About Japanese Area Code of PhoneTalking About Japanese Area Code of Phone
Talking About Japanese Area Code of Phone
 
Jesque robust-worker-pool
Jesque robust-worker-poolJesque robust-worker-pool
Jesque robust-worker-pool
 
命名の話
命名の話命名の話
命名の話
 

Ähnlich wie Static analysis for perl

Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
Positive Hack Days
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
Apoorv Diwan
 

Ähnlich wie Static analysis for perl (20)

Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in FirmwareUsing Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in Pharo
 
Test Driven Development of A Static Code Analyzer
Test Driven Development of A Static Code AnalyzerTest Driven Development of A Static Code Analyzer
Test Driven Development of A Static Code Analyzer
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Shellcode mastering
Shellcode masteringShellcode mastering
Shellcode mastering
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
20151117 es lint
20151117 es lint20151117 es lint
20151117 es lint
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code AuditingCNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code Auditing
 
Cassandra Summit Sept 2015 - Real Time Advanced Analytics with Spark and Cass...
Cassandra Summit Sept 2015 - Real Time Advanced Analytics with Spark and Cass...Cassandra Summit Sept 2015 - Real Time Advanced Analytics with Spark and Cass...
Cassandra Summit Sept 2015 - Real Time Advanced Analytics with Spark and Cass...
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
java theory and coding topic power point presentation.pptx
java theory and coding topic power point presentation.pptxjava theory and coding topic power point presentation.pptx
java theory and coding topic power point presentation.pptx
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 

Mehr von moznion

Hachioji.pm 38
Hachioji.pm 38Hachioji.pm 38
Hachioji.pm 38
moznion
 
Hachiojipm 36
Hachiojipm 36Hachiojipm 36
Hachiojipm 36
moznion
 
Net stalking with-lastfm
Net stalking with-lastfmNet stalking with-lastfm
Net stalking with-lastfm
moznion
 
Hachiojipm 28
Hachiojipm 28Hachiojipm 28
Hachiojipm 28
moznion
 
Hachioji pm 25
Hachioji pm 25Hachioji pm 25
Hachioji pm 25
moznion
 

Mehr von moznion (20)

Hachioji persec
Hachioji persecHachioji persec
Hachioji persec
 
Inner world of Perl::Lint
Inner world of Perl::LintInner world of Perl::Lint
Inner world of Perl::Lint
 
Hachiojipm 44
Hachiojipm 44Hachiojipm 44
Hachiojipm 44
 
Perl::Lint is over, for the present
Perl::Lint is over, for the presentPerl::Lint is over, for the present
Perl::Lint is over, for the present
 
Hachioji pm 41
Hachioji pm 41Hachioji pm 41
Hachioji pm 41
 
Hachioji.pm 40
Hachioji.pm 40Hachioji.pm 40
Hachioji.pm 40
 
Hachioji.pm #39
Hachioji.pm #39Hachioji.pm #39
Hachioji.pm #39
 
Hachioji.pm 38
Hachioji.pm 38Hachioji.pm 38
Hachioji.pm 38
 
Hokkaido.pm #11
Hokkaido.pm #11Hokkaido.pm #11
Hokkaido.pm #11
 
Hachiojipm 36
Hachiojipm 36Hachiojipm 36
Hachiojipm 36
 
Plack::Request with Encoding
Plack::Request with EncodingPlack::Request with Encoding
Plack::Request with Encoding
 
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使うYAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う
YAPC::Asia 2013 - CPAN Testers Reports の情報を上手に使う
 
Net stalking with-lastfm
Net stalking with-lastfmNet stalking with-lastfm
Net stalking with-lastfm
 
Takao.mt 2013
Takao.mt 2013Takao.mt 2013
Takao.mt 2013
 
Perl beginners #08
Perl beginners #08Perl beginners #08
Perl beginners #08
 
Hachiojipm 28
Hachiojipm 28Hachiojipm 28
Hachiojipm 28
 
Hachiojipm 26
Hachiojipm 26Hachiojipm 26
Hachiojipm 26
 
Hachioji pm 25
Hachioji pm 25Hachioji pm 25
Hachioji pm 25
 
Hokkaido pm 8 LT
Hokkaido pm 8 LTHokkaido pm 8 LT
Hokkaido pm 8 LT
 
You Can Be a CPAN Auhor
You Can Be a CPAN AuhorYou Can Be a CPAN Auhor
You Can Be a CPAN Auhor
 

Kürzlich hochgeladen

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

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...
 
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
 
[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
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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?
 
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...
 
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
 

Static analysis for perl