Enterprise Perl
Total Page:16
File Type:pdf, Size:1020Kb
Enterprise Perl Jacinta Richardson Paul Fenwick Enterprise Perl by Jacinta Richardson and Paul Fenwick Copyright © 2009 Jacinta Richardson ([email protected]) Copyright © 2009 Paul Fenwick ([email protected]) Copyright © 2009 Perl Training Australia (http://perltraining.com.au) Conventions used throughout this text are based upon the conventions used in the Netizen training manuals by Kirrily Robert, and found at http://sourceforge.net/projects/spork Distribution of this work is prohibited unless prior permission is obtained from the copyright holder. These notes represent a work-in-progress for Perl Training Australia’s upcoming "Enterprise Perl" course. The OSCON tutorial, "Doing Perl Right", is intended as a heavily condensed version of this course for a conference setting. As these notes are a work-in-progress, the authors apologise for any omissions, mistakes, and completely missing sections that may exist. Updated copies of these notes will become available for free on Perl Training Australia’s course notes page, at http://www.perltraining.com.au/notes.html. This is revision 0.1-alpha-oscon of Perl Training Australia’s "Enterprise Perl" training manual. Table of Contents 1. About Perl Training Australia....................................................................................................... 1 Training.......................................................................................................................................1 Consulting ...................................................................................................................................1 Contact us....................................................................................................................................1 2. Rationale..........................................................................................................................................2 The moving target of "best practice"...........................................................................................2 "Perl Best Practices" by Dr Damian Conway.................................................................... 2 Focus of this course..................................................................................................................... 2 Intended audience ....................................................................................................................... 2 3. Starting a Project............................................................................................................................4 Things to consider....................................................................................................................... 4 Perl’s modules.............................................................................................................................4 Module locations ............................................................................................................... 5 Building a module with Module::Starter ....................................................................................5 Using module-starter ......................................................................................................... 6 Configuration ........................................................................................................... 6 A skeleton tour .................................................................................................................. 6 Encapsulation and big systems ...................................................................................................8 Class exercise .................................................................................................................... 8 Further information ........................................................................................................... 9 4. Accessing Perl’s documentation with perldoc............................................................................10 perldoc.......................................................................................................................................10 Module documentation .............................................................................................................10 Function documentation............................................................................................................11 Questions and answers..............................................................................................................11 General pages............................................................................................................................11 Tutorials...........................................................................................................................11 Writing your own POD (Plain Old Documentation).................................................................12 Paragraphs .......................................................................................................................12 An example......................................................................................................................14 5. Testing ............................................................................................................................................16 Oh no! .......................................................................................................................................16 POD Testing..............................................................................................................................16 Test::Pod ..........................................................................................................................16 Test::Pod::Coverage.........................................................................................................16 Trying it out.....................................................................................................................17 Testing Strategies ......................................................................................................................17 Black box testing .............................................................................................................17 White box testing.............................................................................................................18 Testing your code ......................................................................................................................18 Test::Harness ...................................................................................................................18 Test::More........................................................................................................................19 Coverage testing and Devel::Cover .................................................................................20 Putting it all together, an example.............................................................................................21 Our module......................................................................................................................21 Some tests........................................................................................................................23 Test results.......................................................................................................................24 Results from running test.t directly:...................................................................24 Perl Training Australia (http://perltraining.com.au/) iii Results from running tests using test harness........................................................25 Results from running tests compiled with Devel::Cover.......................................25 Good tests..................................................................................................................................29 Chapter summary ......................................................................................................................30 6. Writing good code.........................................................................................................................31 Perl::Critic - automatically review your code ...........................................................................31 Levels of severity.............................................................................................................31 Perl::Critic online ............................................................................................................31 perlcritic on the command-line........................................................................................31 Understanding the output.......................................................................................32 Excluding and including rules ...............................................................................33 Profiles ...................................................................................................................33 Perl::Critic and testing.....................................................................................................33 Progressive testing .................................................................................................34 Further reading ................................................................................................................34 7. autodie - The art of Klingon Programming ...............................................................................35