Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Learning Perl Objects, References & Modules
A Note Regarding Supplemental Files
Foreword
Preface
Structure of This Book
Conventions Used in This Book
Comments and Questions
Acknowledgments
1. Introduction
What Should You Know Already?
What About All Those Footnotes?
What’s with the Exercises?
What if I’m a Perl Course Instructor?
2. Building Larger Programs
The Cure for the Common Code
Inserting Code with eval
Using do
Using require
require and @INC
Extending @INC
Extending @INC with PERL5LIB
Extending @INC with -I
The Problem of Namespace Collisions
Packages as Namespace Separators
Scope of a Package Directive
Packages and Lexicals
Exercises
Exercise 1 [30 min]
Exercise 2 [10 min]
3. Introduction to References
Performing 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
Exercise 1 [5 min]
Exercise 2 [30 min]
4. References and Scoping
More 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
Exercise 1 [5 min]
Exercise 2 [30 min]
5. Manipulating Complex Data Structures
Using 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
Exercise 1 [20 min]
Exercise 2 [5 min]
6. Subroutine References
Referencing a Named Subroutine
Anonymous Subroutines
Callbacks
Closures
Returning a Subroutine from a Subroutine
Closure Variables as Inputs
Closure Variables as Static Local Variables
Exercise
Exercise [30 min]
7. Practical Reference Tricks
Review of Sorting
Sorting with Indices
Sorting Efficiently
The Schwartzian Transform
Recursively Defined Data
Building Recursively Defined Data
Displaying Recursively Defined Data
Exercises
Exercise 1 [15 min]
Exercise 2 [15 min]
Exercise 3 [10 min]
Exercise 4 [20 min]
8. Introduction to Objects
If 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
Exercise 1 [20 min]
Exercise 2 [40 min]
9. Objects with Data
A 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
Exercise [45 min]
10. Object Destruction
Nested Object Destruction
Beating a Dead Horse
Indirect Object Notation
Additional Instance Variables in Subclasses
Using Class Variables
Weakening the Argument
Exercise
Exercise [45 min]
11. Some Advanced Object Topics
UNIVERSAL 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
Exercise [30 min]
12. Using Modules
Sample 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
Exercise [15 min]
13. Writing a Distribution
Starting 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
Exercise [30 min]
14. Essential Testing
What 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
Exercise [60 min]
15. Contributing to CPAN
The 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
Exercise
A. Answers to Exercises
Answers for Chapter 2
Exercise 1 (Exercise 1 [30 min])
Exercise 2 (Exercise 2 [10 min])
Answers for Chapter 3
Exercise 1 (Exercise 1 [5 min])
Exercise 2 (Exercise 2 [30 min])
Answers for Chapter 4
Exercise 1 (Exercise 1 [5 min])
Exercise 2 (Exercise 2 [30 min])
Answers for Chapter 5
Exercise 1 (Exercise 1 [20 min])
Exercise 2 (Exercise 2 [5 min])
Answer for Chapter 6
Exercise (Exercise [30 min])
Answers for Chapter 7
Exercise 1 (Exercise 1 [15 min])
Exercise 2 (Exercise 2 [15 min])
Exercise 3 (Exercise 3 [10 min])
Exercise 4 (Exercise 4 [20 min])
Answers for Chapter 8
Exercise 1 (Exercise 1 [20 min])
Exercise 2 (Exercise 2 [40 min])
Answer for Chapter 9
Exercise (Exercise [45 min])
Answer for Chapter 10
Exercise (Exercise [45 min])
Answer for Chapter 11
Exercise (Exercise [30 min])
Answer for Chapter 12
Exercise (Exercise [15 min])
Answers for Chapters 13-15
Index
About the Authors
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →