O’Reilly, 2003. — 240 p. — ISBN: 0-596-00478-8.
Learning Perl Objects, References & Modules picks up where Learning Perl leaves off. This new book offers a gentle introduction to the world of references, object-oriented programming, and the use of Perl modules that form the backbone of any effective Perl program. Following the successful format of Learning Perl, each chapter in the book is designed to be small enough to be read in just an hour or two. Each chapter ends with a series of exercises to help you practice what you've learned with answers in an appendix for your reference. In short, this book covers everything that separates the Perl dabbler from the Perl programmer.
What Should You Know Already?
What About All Those Footnotes?
What's with the Exercises?
What if I'm a Perl Course Instructor?
Building Larger ProgramsThe Cure for the Common Code
Inserting Code with eval
Using do
Using require
require and @INC
The Problem of Namespace Collisions
Packages as Namespace Separators
Scope of a Package Directive
Packages and Lexicals
Exercises
Introduction to ReferencesPerforming the Same Task on Many Arrays
Taking a Reference to an Array
Dereferencing the Array Reference
Dropping Those Braces
Modifying the Array
Nested Data Structures
Simplifying Nested Element References with Arrows
References to Hashes
Exercises
References and ScopingMore than One Reference to Data
What if That Was the Name?
Reference Counting and Nested Data Structures
When Reference Counting Goes Bad
Creating an Anonymous Array Directly
Creating an Anonymous Hash
Autovivification
Autovivification and Hashes
Exercises
Manipulating Complex Data StructuresUsing the Debugger to View Complex Data
Viewing Complex Data with Data::Dumper
Storing Complex Data with Storable
The map and grep Operators
Using map
Applying a Bit of Indirection
Selecting and Altering Complex Data
Exercises
Subroutine ReferencesReferencing a Named Subroutine
Anonymous Subroutines
Callbacks
Closures
Returning a Subroutine from a Subroutine
Closure Variables as Inputs
Closure Variables as Static Local Variables
Exercise
Practical Reference TricksReview of Sorting
Sorting with Indices
Sorting Efficiently
The Schwartzian Transform
Recursively Defined Data
Building Recursively Defined Data
Displaying Recursively Defined Data
Exercises
Introduction to ObjectsIf We Could Talk to the Animals...
Introducing the Method Invocation Arrow
The Extra Parameter of Method Invocation
Calling a Second Method to Simplify Things
A Few Notes About @ISA
Overriding the Methods
Starting the Search from a Different Place
The SUPER Way of Doing Things
What to Do with @_
Where We Are So Far...
Exercises
Objects with DataA Horse Is a Horse, of Course of Course—or Is It?
Invoking an Instance Method
Accessing the Instance Data
How to Build a Horse
Inheriting the Constructor
Making a Method Work with Either Classes or Instances
Adding Parameters to a Method
More Interesting Instances
A Horse of a Different Color
Getting Your Deposit Back
Don't Look Inside the Box
Faster Getters and Setters
Getters That Double as Setters
Restricting a Method to Class-Only or Instance-Only
Exercise
Object DestructionNested Object Destruction
Beating a Dead Horse
Indirect Object Notation
Additional Instance Variables in Subclasses
Using Class Variables
Weakening the Argument
Exercise
Some Advanced Object TopicsUNIVERSAL Methods
Testing Your Objects for Good Behavior
AUTOLOAD as a Last Resort
Using AUTOLOAD for Accessors
Creating Getters and Setters More Easily
Multiple Inheritance
References to Filehandles
Exercise
Using ModulesSample Function-Oriented Interface: File::Basename
Selecting What to Import
Sample Object-Oriented Interface: File::Spec
A More Typical Object-Oriented Module: Math::BigInt
The Differences Between OO and Non-OO Modules
What use Is Doing
Setting the Path at the Right Time
Importing with Exporter
@EXPORT and @EXPORT_OK
Exporting in a Primarily OO Module
Custom Import Routines
Exercise
Writing a DistributionStarting with h2xs
Looking at the Templates
The Prototype Module Itself
Embedded Documentation
Controlling the Distribution with Makefile.PL
Alternate Installation Locations (PREFIX=...)
Trivial make test
Trivial make install
Trivial make dist
Using the Alternate Library Location
Exercise
Essential TestingWhat the Test Harness Does
Writing Tests with Test::Simple
Writing Tests with Test::More
Conditional Tests
More Complex Tests (Multiple Test Scripts)
Testing Things That Write to STDOUT and STDERR
Exercise
Contributing to CPANThe Comprehensive Perl Archive Network
Getting Prepared
Preparing Your Distribution
Uploading Your Distribution
Announcing the Module
Testing on Multiple Platforms
Consider Writing an Article or Giving a Talk
Exercise
Answers to Exercises