SlideShare a Scribd company logo
An Introduction To Perl Critic Nordic Perl Workshop 2007 An Introduction To Perl Critic Josh McAdams
An Introduction To Perl Critic Nordic Perl Workshop 2007 What is Perl Critic? - Think 'use warnings' or 'use strict' ... only more (or less) - Why more? ... Perl Critic looks beyond mere syntatical correctness - for instance, are you using CamelCase sub names? - Why less? ... Perl Critic doesn't actually compile your code - Your code is parsed as a 'document' thanks to PPI - Invalid code could possibly pass a critique
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example #!/usr/bin/perl print “Hello, Denmark”; ... okay, a VERY basic example Here's the code...
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example --(0)> perlcritic hello_denmark.pl  Code before strictures are enabled at line 3, column 1.  See page 429 of PBP.  (Severity: 5) ... what, we have problems? So, let's run perlcritic...
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example --(0)> perlcritic hello_denmark.pl  Code before strictures are enabled at line 3, column 1.  See page 429 of PBP.  (Severity: 5) What just happened... We ran the 'perlcritic' program and it complained about a violation in our code at a specific line and column and even told us where in PBP we can find why this is bad code! and how bad our code is
An Introduction To Perl Critic Nordic Perl Workshop 2007 Perl Critic Policies - What is Perl Critic judging our code on? ... Policies ... in this case TestingAndDebugging::RequireUseStrict - What are Policies? ...  rules that perl critic enforces ... perl critic is packaged with many ... the can be big things that are probably bugs (or example) ... or little things that are mostly cosmetic ... found in the Perl::Critic::Policy namespace - Who comes up with these Policies? ... the Perl Critic maintainers ... Perl Critic extension authors ... You ... let's see an example of a cosmetic policy
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Cosmetic Example #!/usr/bin/perl use strict; use warnings; sub CamelCaseSub { print "Hey, I'm a CamelCase subroutine"; return; } CamelCaseSub(); Here's the code... ... any idea of what the error will be?
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Cosmetic Example --(0)> perlcritic -severity 1 cosmetic.pl  Use Emacs file variables to declare coding style at line 1, column 1.  Emacs can read per-file settings.  (Severity: 2) RCS keywords $Id$ not found at line 1, column 1.  See page 441 of PBP.  (Severity: 2) RCS keywords $Revision$, $HeadURL$, $Date$ not found at line 1, column 1.  See page 441 of PBP.  (Severity: 2) RCS keywords $Revision$, $Source$, $Date$ not found at line 1, column 1.  See page 441 of PBP.  (Severity: 2) Missing Perl version at line 1, column 1.  Add "use v5.6.0" or similar.  (Severity: 1) No "VERSION" variable found at line 1, column 1.  See page 404 of PBP.  (Severity: 2) Mixed-case subroutine name at line 6, column 1.  See page 44 of PBP.  (Severity: 1) ... ugh, that's more than we expected? So, let's run perlcritic...
An Introduction To Perl Critic Nordic Perl Workshop 2007 Policy Severity - Who opened the flood gates? ... we did, by asking for a new severity - What are severities? ...  weights assigned to policies ... most severe violation = 5 ... least severe violation = 1 - Who assigns these severities? ... module authors ... if you disagree, you can change the severity
An Introduction To Perl Critic Nordic Perl Workshop 2007 Severity Levels -  What are the severity levels? 5 = gentle (the only one checked by default) 4 = stern 3 = harsh 2 = cruel 1 = brutal - When you request any severity you get all severities above that level - You can request a severity level by number or by name - It can be helpful to start examining your code at gentle and work your way down
An Introduction To Perl Critic Nordic Perl Workshop 2007 Another Example #!/usr/bin/perl -*- cperl -*- # $Id$ use strict; use warnings; use Config; our $VERSION = 1; print "Hipster" if  $Config{'osname'} eq 'darwin'; Here's the code... ... any idea of what the error will be?
An Introduction To Perl Critic Nordic Perl Workshop 2007 Another Example --(0)> perlcritic -severity 2 trailing_if.pl  Postfix control "if" used at line 11, column 19.  See pages 93,94 of PBP.  (Severity: 2) ... but what if I like the trailing if? So, let's run perlcritic...
An Introduction To Perl Critic Nordic Perl Workshop 2007 Excluding Policies --(0)> perlcritic -2 -exclude ProhibitPostfixControls  trailing_if.pl trailing_if.pl source OK ... that's what I wanted, but what a PITA I can exclude policies that I disagree with on the command line...
An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration - How about making my preferences persistent? ... sure, just create a .perlcriticrc file - .perlcriticrc? ...  it's just a configuration file with your preferences ... basically an INI file format ... place it in your home directory ... or specify it on the command line ... let's see a file
An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> cat ~/.perlcriticrc exclude = ControlStructures::ProhibitPostfixControls ... an admittingly lame configuration file Let's see the file...
An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> perlcritic -2 trailing_if.pl  trailing_if.pl source OK ... let's see something cooler But it does the trick...
An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> cat ~/.perlcriticrc severity = 2 top = 5 exclude = Editor::RequireEmacsFileVariables Miscellanea::RequireRcsKeywords  [ControlStructures::ProhibitPostfixControls] severity = 4 allow = if unless theme = iffy Here's a more interesting file... ... theme? The default severity to report How many violations to report Policies to ignore Change the default severity for a policy Pass arguments to the policy constructor, in this case telling it to allow trailing ifs and unlesses Apply a new theme
An Introduction To Perl Critic Nordic Perl Workshop 2007 Themes - What are these themes you speak of? ... similar to tags or labels ... think del.icio.us ... themes classify Policies and allow them to be grouped together for purposes of running or excluding - What are some common themes? core = the policies that come packaged with Perl Critic pbp = policies that apply to Perl Best Practices bugs = policies that typically indicate bugs in your code ... there are many/infinitely more, just look at the policy docs
An Introduction To Perl Critic Nordic Perl Workshop 2007 Specifying Themes --(0)>  perlcritic -theme '(pbp || (bugs && security)) && !cosmetic' trailing_if.pl  trailing_if.pl source OK ... do a 'perlcritic -list' to see all policies, themes, and severities Let's specify themes to look for...
An Introduction To Perl Critic Nordic Perl Workshop 2007 I Want To Be Good, I Just Can't - What happens if I want to respect a policy, but for some reason can't in this one instance? ... for instance sub-classing DBI and overriding 'connect' package DBIxUseless; use warnings; use strict; use base qw(DBI); our $VERSION = 1; sub connect { return shift->SUPER::connect(@_) } 1;
An Introduction To Perl Critic Nordic Perl Workshop 2007 But He Made Me Do It --(0)>  perlcritic DBIxUseless.pm  Subroutine name is a homonym for builtin function at line 9, column 1.  See page 177 of PBP.  (Severity: 4) ... doh, I can't help it, I have to override 'connect' Let's see what happens...
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Pseudo-Solution package DBIxUseless; use warnings; use strict; use base qw(DBI); our $VERSION = 1; sub connect { ## no critic (ProhibitBuiltinHomonyms) return shift->SUPER::connect(@_)  } 1; Pseudo-pragma allows for you to turn off all or specific criticisms for individual lines of code or blocks of code (in this case)
An Introduction To Perl Critic Nordic Perl Workshop 2007 A Pseudo-Solution #!/usr/bin/perl use warnings; use strict; ## no critic (ProhibitPostfixControls) print “Hi” if $^O eq 'darwin'; print “Hello” if $^O =~ /win/i; ## use critic - This even works with themes You can also create sections of your code that are not meant for critique
An Introduction To Perl Critic Nordic Perl Workshop 2007 Review - That is Perl Critic in a nutshell ...  the system consists of a bunch of policies ... that have a name ... and a severity ... and one (maybe zero) or more themes ... the system can be configured ... by selectively blocking off criticism for specific code ... by ignoring policies ... by changing the severity of policies ... by looking a specific themes ... by tweaking the policies ... severity ... themes ... configuration ... but you still have to remember to run perlcritic, unless
An Introduction To Perl Critic Nordic Perl Workshop 2007 Criticism Pragma - You use the criticism pragma package DBIxUseless; use warnings; use strict; use base qw(DBI); use criticism; our $VERSION = 1; sub connect { return shift->SUPER::connect(@_) } 1;
An Introduction To Perl Critic Nordic Perl Workshop 2007 Criticism Pragma -  The criticism pragma ... runs Perl Critic every time you run your code ... keeps you from having to remember to run perlcritic ... creates additional runtime overhead ... is easy to accidentally leave in your production code ... there has to be a better way
An Introduction To Perl Critic Nordic Perl Workshop 2007 Test::Perl::Critic -  Test::Perl::Critic ... criticism in your test suite ... now when you run 'make test', you get Perl Critic ... but it's not good to distribute these test in public modules ... these should be for development only ... you don't want your modules not installing because  of Perl Critic use Test::Perl::Critic; all_critic_ok();
An Introduction To Perl Critic Nordic Perl Workshop 2007 In Review -  Perl Critic is ... a highly-configurable static source code analyzer ... a tool to help you write better code ... a reminder of good coding practices ... an easily extendable system (see tomorrows talk) ... a development aid, not a distribution dependency ... not a  guarantee  that you'll write quality code

More Related Content

What's hot

Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
Elizabeth Smith
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
dn
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
Will Shen
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
Siddhi
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
Mike Lively
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
cbcunc
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
YeurDreamin'
 
PHPUnit
PHPUnitPHPUnit
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentals
cbcunc
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVM
Min-Yih Hsu
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Giorgio Sironi
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
nicobn
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
Jason Noble
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
Thanh Robi
 
Perl Modules
Perl ModulesPerl Modules
Perl Modules
stn_tkiller
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
Paweł Michalik
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
varuntaliyan
 
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
Sebastian Marek
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 

What's hot (20)

Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentals
 
Handling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVMHandling inline assembly in Clang and LLVM
Handling inline assembly in Clang and LLVM
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Perl Modules
Perl ModulesPerl Modules
Perl Modules
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 

Similar to An Introduction To Perl Critic

YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
joshua.mcadams
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
Workhorse Computing
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::Class
Curtis Poe
 
Puppet Loves RSpec, Why You Should, Too
Puppet Loves RSpec, Why You Should, TooPuppet Loves RSpec, Why You Should, Too
Puppet Loves RSpec, Why You Should, Too
Puppet
 
Puppet loves RSpec, why you should, too
Puppet loves RSpec, why you should, tooPuppet loves RSpec, why you should, too
Puppet loves RSpec, why you should, too
Dennis Rowe
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
perlall
perlallperlall
perlall
Reini Urban
 
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Alex Balhatchet
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
Dave Cross
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
Mike Lively
 
Weird Plsql
Weird PlsqlWeird Plsql
Weird Plsql
webanddb
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
Cory Foy
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
CiaranMcNulty
 
Coding standard
Coding standardCoding standard
Coding standard
FAROOK Samath
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
nottings
 
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamAutomated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Puppet
 
Perl 20tips
Perl 20tipsPerl 20tips
Perl 20tips
Ravi Kumar
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
daoswald
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
tutorialsruby
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
tutorialsruby
 

Similar to An Introduction To Perl Critic (20)

YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::Class
 
Puppet Loves RSpec, Why You Should, Too
Puppet Loves RSpec, Why You Should, TooPuppet Loves RSpec, Why You Should, Too
Puppet Loves RSpec, Why You Should, Too
 
Puppet loves RSpec, why you should, too
Puppet loves RSpec, why you should, tooPuppet loves RSpec, why you should, too
Puppet loves RSpec, why you should, too
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
perlall
perlallperlall
perlall
 
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Weird Plsql
Weird PlsqlWeird Plsql
Weird Plsql
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
 
Coding standard
Coding standardCoding standard
Coding standard
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
 
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott NottinghamAutomated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
Automated Puppet Testing - PuppetCamp Chicago '12 - Scott Nottingham
 
Perl 20tips
Perl 20tipsPerl 20tips
Perl 20tips
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 

More from joshua.mcadams

Open Flash Chart And Perl
Open Flash Chart And PerlOpen Flash Chart And Perl
Open Flash Chart And Perl
joshua.mcadams
 
Introduction To Testing With Perl
Introduction To Testing With PerlIntroduction To Testing With Perl
Introduction To Testing With Perl
joshua.mcadams
 
Thank A Cpan Contributor Today
Thank A Cpan Contributor TodayThank A Cpan Contributor Today
Thank A Cpan Contributor Today
joshua.mcadams
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
joshua.mcadams
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Coding
joshua.mcadams
 
Lightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To ScrumLightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To Scrum
joshua.mcadams
 

More from joshua.mcadams (6)

Open Flash Chart And Perl
Open Flash Chart And PerlOpen Flash Chart And Perl
Open Flash Chart And Perl
 
Introduction To Testing With Perl
Introduction To Testing With PerlIntroduction To Testing With Perl
Introduction To Testing With Perl
 
Thank A Cpan Contributor Today
Thank A Cpan Contributor TodayThank A Cpan Contributor Today
Thank A Cpan Contributor Today
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Coding
 
Lightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To ScrumLightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To Scrum
 

Recently uploaded

Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
moinahousna
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Muhammad Ali
 
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Nicolás Lopéz
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
Priyanka Aash
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
ldtexsolbl
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Kunal Gupta
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
Axel Rennoch
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 

Recently uploaded (20)

Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
 
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 

An Introduction To Perl Critic

  • 1. An Introduction To Perl Critic Nordic Perl Workshop 2007 An Introduction To Perl Critic Josh McAdams
  • 2. An Introduction To Perl Critic Nordic Perl Workshop 2007 What is Perl Critic? - Think 'use warnings' or 'use strict' ... only more (or less) - Why more? ... Perl Critic looks beyond mere syntatical correctness - for instance, are you using CamelCase sub names? - Why less? ... Perl Critic doesn't actually compile your code - Your code is parsed as a 'document' thanks to PPI - Invalid code could possibly pass a critique
  • 3. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example #!/usr/bin/perl print “Hello, Denmark”; ... okay, a VERY basic example Here's the code...
  • 4. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example --(0)> perlcritic hello_denmark.pl Code before strictures are enabled at line 3, column 1. See page 429 of PBP. (Severity: 5) ... what, we have problems? So, let's run perlcritic...
  • 5. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Basic Example --(0)> perlcritic hello_denmark.pl Code before strictures are enabled at line 3, column 1. See page 429 of PBP. (Severity: 5) What just happened... We ran the 'perlcritic' program and it complained about a violation in our code at a specific line and column and even told us where in PBP we can find why this is bad code! and how bad our code is
  • 6. An Introduction To Perl Critic Nordic Perl Workshop 2007 Perl Critic Policies - What is Perl Critic judging our code on? ... Policies ... in this case TestingAndDebugging::RequireUseStrict - What are Policies? ... rules that perl critic enforces ... perl critic is packaged with many ... the can be big things that are probably bugs (or example) ... or little things that are mostly cosmetic ... found in the Perl::Critic::Policy namespace - Who comes up with these Policies? ... the Perl Critic maintainers ... Perl Critic extension authors ... You ... let's see an example of a cosmetic policy
  • 7. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Cosmetic Example #!/usr/bin/perl use strict; use warnings; sub CamelCaseSub { print "Hey, I'm a CamelCase subroutine"; return; } CamelCaseSub(); Here's the code... ... any idea of what the error will be?
  • 8. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Cosmetic Example --(0)> perlcritic -severity 1 cosmetic.pl Use Emacs file variables to declare coding style at line 1, column 1. Emacs can read per-file settings. (Severity: 2) RCS keywords $Id$ not found at line 1, column 1. See page 441 of PBP. (Severity: 2) RCS keywords $Revision$, $HeadURL$, $Date$ not found at line 1, column 1. See page 441 of PBP. (Severity: 2) RCS keywords $Revision$, $Source$, $Date$ not found at line 1, column 1. See page 441 of PBP. (Severity: 2) Missing Perl version at line 1, column 1. Add "use v5.6.0" or similar. (Severity: 1) No "VERSION" variable found at line 1, column 1. See page 404 of PBP. (Severity: 2) Mixed-case subroutine name at line 6, column 1. See page 44 of PBP. (Severity: 1) ... ugh, that's more than we expected? So, let's run perlcritic...
  • 9. An Introduction To Perl Critic Nordic Perl Workshop 2007 Policy Severity - Who opened the flood gates? ... we did, by asking for a new severity - What are severities? ... weights assigned to policies ... most severe violation = 5 ... least severe violation = 1 - Who assigns these severities? ... module authors ... if you disagree, you can change the severity
  • 10. An Introduction To Perl Critic Nordic Perl Workshop 2007 Severity Levels - What are the severity levels? 5 = gentle (the only one checked by default) 4 = stern 3 = harsh 2 = cruel 1 = brutal - When you request any severity you get all severities above that level - You can request a severity level by number or by name - It can be helpful to start examining your code at gentle and work your way down
  • 11. An Introduction To Perl Critic Nordic Perl Workshop 2007 Another Example #!/usr/bin/perl -*- cperl -*- # $Id$ use strict; use warnings; use Config; our $VERSION = 1; print "Hipster" if $Config{'osname'} eq 'darwin'; Here's the code... ... any idea of what the error will be?
  • 12. An Introduction To Perl Critic Nordic Perl Workshop 2007 Another Example --(0)> perlcritic -severity 2 trailing_if.pl Postfix control "if" used at line 11, column 19. See pages 93,94 of PBP. (Severity: 2) ... but what if I like the trailing if? So, let's run perlcritic...
  • 13. An Introduction To Perl Critic Nordic Perl Workshop 2007 Excluding Policies --(0)> perlcritic -2 -exclude ProhibitPostfixControls trailing_if.pl trailing_if.pl source OK ... that's what I wanted, but what a PITA I can exclude policies that I disagree with on the command line...
  • 14. An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration - How about making my preferences persistent? ... sure, just create a .perlcriticrc file - .perlcriticrc? ... it's just a configuration file with your preferences ... basically an INI file format ... place it in your home directory ... or specify it on the command line ... let's see a file
  • 15. An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> cat ~/.perlcriticrc exclude = ControlStructures::ProhibitPostfixControls ... an admittingly lame configuration file Let's see the file...
  • 16. An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> perlcritic -2 trailing_if.pl trailing_if.pl source OK ... let's see something cooler But it does the trick...
  • 17. An Introduction To Perl Critic Nordic Perl Workshop 2007 Persistent Configuration --(0)> cat ~/.perlcriticrc severity = 2 top = 5 exclude = Editor::RequireEmacsFileVariables Miscellanea::RequireRcsKeywords [ControlStructures::ProhibitPostfixControls] severity = 4 allow = if unless theme = iffy Here's a more interesting file... ... theme? The default severity to report How many violations to report Policies to ignore Change the default severity for a policy Pass arguments to the policy constructor, in this case telling it to allow trailing ifs and unlesses Apply a new theme
  • 18. An Introduction To Perl Critic Nordic Perl Workshop 2007 Themes - What are these themes you speak of? ... similar to tags or labels ... think del.icio.us ... themes classify Policies and allow them to be grouped together for purposes of running or excluding - What are some common themes? core = the policies that come packaged with Perl Critic pbp = policies that apply to Perl Best Practices bugs = policies that typically indicate bugs in your code ... there are many/infinitely more, just look at the policy docs
  • 19. An Introduction To Perl Critic Nordic Perl Workshop 2007 Specifying Themes --(0)> perlcritic -theme '(pbp || (bugs && security)) && !cosmetic' trailing_if.pl trailing_if.pl source OK ... do a 'perlcritic -list' to see all policies, themes, and severities Let's specify themes to look for...
  • 20. An Introduction To Perl Critic Nordic Perl Workshop 2007 I Want To Be Good, I Just Can't - What happens if I want to respect a policy, but for some reason can't in this one instance? ... for instance sub-classing DBI and overriding 'connect' package DBIxUseless; use warnings; use strict; use base qw(DBI); our $VERSION = 1; sub connect { return shift->SUPER::connect(@_) } 1;
  • 21. An Introduction To Perl Critic Nordic Perl Workshop 2007 But He Made Me Do It --(0)> perlcritic DBIxUseless.pm Subroutine name is a homonym for builtin function at line 9, column 1. See page 177 of PBP. (Severity: 4) ... doh, I can't help it, I have to override 'connect' Let's see what happens...
  • 22. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Pseudo-Solution package DBIxUseless; use warnings; use strict; use base qw(DBI); our $VERSION = 1; sub connect { ## no critic (ProhibitBuiltinHomonyms) return shift->SUPER::connect(@_) } 1; Pseudo-pragma allows for you to turn off all or specific criticisms for individual lines of code or blocks of code (in this case)
  • 23. An Introduction To Perl Critic Nordic Perl Workshop 2007 A Pseudo-Solution #!/usr/bin/perl use warnings; use strict; ## no critic (ProhibitPostfixControls) print “Hi” if $^O eq 'darwin'; print “Hello” if $^O =~ /win/i; ## use critic - This even works with themes You can also create sections of your code that are not meant for critique
  • 24. An Introduction To Perl Critic Nordic Perl Workshop 2007 Review - That is Perl Critic in a nutshell ... the system consists of a bunch of policies ... that have a name ... and a severity ... and one (maybe zero) or more themes ... the system can be configured ... by selectively blocking off criticism for specific code ... by ignoring policies ... by changing the severity of policies ... by looking a specific themes ... by tweaking the policies ... severity ... themes ... configuration ... but you still have to remember to run perlcritic, unless
  • 25. An Introduction To Perl Critic Nordic Perl Workshop 2007 Criticism Pragma - You use the criticism pragma package DBIxUseless; use warnings; use strict; use base qw(DBI); use criticism; our $VERSION = 1; sub connect { return shift->SUPER::connect(@_) } 1;
  • 26. An Introduction To Perl Critic Nordic Perl Workshop 2007 Criticism Pragma - The criticism pragma ... runs Perl Critic every time you run your code ... keeps you from having to remember to run perlcritic ... creates additional runtime overhead ... is easy to accidentally leave in your production code ... there has to be a better way
  • 27. An Introduction To Perl Critic Nordic Perl Workshop 2007 Test::Perl::Critic - Test::Perl::Critic ... criticism in your test suite ... now when you run 'make test', you get Perl Critic ... but it's not good to distribute these test in public modules ... these should be for development only ... you don't want your modules not installing because of Perl Critic use Test::Perl::Critic; all_critic_ok();
  • 28. An Introduction To Perl Critic Nordic Perl Workshop 2007 In Review - Perl Critic is ... a highly-configurable static source code analyzer ... a tool to help you write better code ... a reminder of good coding practices ... an easily extendable system (see tomorrows talk) ... a development aid, not a distribution dependency ... not a guarantee that you'll write quality code