refactoring tools for perl code
DESCRIPTION
Slides from presentation at Mojoconf. Discusses my Extract Method refactoring implementation for Perl.TRANSCRIPT
REFACTORING TOOLS IN PERL
WHAT IS REFACTORINGRefactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior
REFACTORING CATALOG
• ▶Add Parameter
• ▶Change Bidirectional Association to Unidirectional
• ▶Change Reference to Value
• ▶Change Unidirectional Association to Bidirectional
• ▶Change Value to Reference
• ▶Collapse Hierarchy
• ▶Consolidate Conditional Expression
• ▶Consolidate Duplicate Conditional Fragments
• ▶Decompose Conditional
• ▶Duplicate Observed Data
• ▶Dynamic Method Definition
• ▶Eagerly Initialized Attribute
• ▶Encapsulate Collection
THE GOALS
• Make code more readable and comprehensible
• Eliminate duplication
WHY?
• Lots of time is spent reading code
• Bugs hide in obscure code
• Duplication makes code rot
• LEARNING!
START OUT BRAINDEAD, GET BETTER
TOOLS?????
JAVA REFACTORINGIn Eclipse
JAVASCRIPT REFACTORINGIn WebStorm
PERL REFACTORING
PPIx::EditorTools
• Supports Vim and Emacs
• RenameVariable (safe renaming)
• RenamePackageFromPath
• IntroduceTemporaryVariable
My extensions
• Supports Vim only
• ExtractMethod
• ConvertVarToAttribute
Why refactor long methods?
• Readability—make the essential logic clear
• Isolated testing
• Isolated editing
• Avoid comments getting out of sync
ARCHITECTUREAnalyzer
VariableSorter
CodeGenerator
CodeEditor
ANALYZER CLASSES
CURRENT STATUS
• Mostly safe with “normal” code.
• No fancy installation available
• Use the README athttps://github.com/dagfinnr/perl-extract-method
• Github, Twitter (theoretically): dagfinnr