• Table of Contents
• Index
• Reviews
• Reader Reviews
• Errata
Learning Perl Objects, References & Modules
By Randal L. Schwartz
Copyright
Foreword
Preface
Structure of This Book
Conventions Used in This Book
Comments and Questions
Acknowledgments
Chapter 1. Introduction
Section 1.1. What Should You Know Already?
Section 1.2. What About All Those Footnotes?
Section 1.3. What''''s with the Exercises?
Section 1.4. What if I''''m a Perl Course Instructor?
Chapter 2. Building Larger Programs
Section 2.1. The Cure for the Common Code
Section 2.2. Inserting Code with eval
Section 2.3. Using do
Section 2.4. Using require
Section 2.5. require and @INC
Section 2.6. The Problem of Namespace Collisions
Section 2.7. Packages as Namespace Separators
Section 2.8. Scope of a Package Directive
Section 2.9. Packages and Lexicals
Section 2.10. Exercises
Chapter 3. Introduction to References
Section 3.1. Performing the Same Task on Many Arrays
Section 3.2. Taking a Reference to an Array
Section 3.3. Dereferencing the Array Reference
Section 3.4. Dropping Those Braces
Section 3.5. Modifying the Array
Section 3.6. Nested Data Structures
Section 3.7. Simplifying Nested Element References with Arrows
Section 3.8. References to Hashes
Section 3.9. Exercises
Chapter 4. References and Scoping
Section 4.1. More than One Reference to Data
Section 4.2. What if That Was the Name?
Section 4.3. Reference Counting and Nested Data Structures
Section 4.4. When Reference Counting Goes Bad
Section 4.5. Creating an Anonymous Array Directly
Section 4.6. Creating an Anonymous Hash
Section 4.7. Autovivification
Section 4.8. Autovivification and Hashes
Section 4.9. Exercises
Chapter 5. Manipulating Complex Data Structures
Section 5.1. Using the Debugger to View Complex Data
Section 5.2. Viewing Complex Data with Data::Dumper
Section 5.3. Storing Complex Data with Storable
Section 5.4. The map and grep Operators
Section 5.5. Using map
Section 5.6. Applying a Bit of Indirection
Section 5.7. Selecting and Altering Complex Data
Section 5.8. Exercises
Chapter 6. Subroutine References
Section 6.1. Referencing a Named Subroutine
Section 6.2. Anonymous Subroutines
Section 6.3. Callbacks
Section 6.4. Closures
Section 6.5. Returning a Subroutine from a Subroutine
Section 6.6. Closure Variables as Inputs
Section 6.7. Closure Variables as Static Local Variables
Section 6.8. Exercise
Chapter 7. Practical Reference Tricks
Section 7.1. Review of Sorting
Section 7.2. Sorting with Indices
Section 7.3. Sorting Efficiently
Section 7.4. The Schwartzian Transform
Section 7.5. Recursively Defined Data
Section 7.6. Building Recursively Defined Data
Section 7.7. Displaying Recursively Defined Data
Section 7.8. Exercises
Chapter 8. Introduction to Objects
Section 8.1. If We Could Talk to the Animals...
Section 8.2. Introducing the Method Invocation Arrow
Section 8.3. The Extra Parameter of Method Invocation
Section 8.4. Calling a Second Method to Simplify Things
Section 8.5. A Few Notes About @ISA
Section 8.6. Overriding the Methods
Section 8.7. Starting the Search from a Different Place
Section 8.8. The SUPER Way of Doing Things
Section 8.9. What to Do with @_
Section 8.10. Where We Are So Far...
Section 8.11. Exercises
Chapter 9. Objects with Data
Section 9.1. A Horse Is a Horse, of Course of Courseor Is It?
Section 9.2. Invoking an Instance Method
Section 9.3. Accessing the Instance Data
Section 9.4. How to Build a Horse
Section 9.5. Inheriting the Constructor
Section 9.6. Making a Method Work with Either Classes or Instances
Section 9.7. Adding Parameters to a Method
Section 9.8. More Interesting Instances
Section 9.9. A Horse of a Different Color
Section 9.10. Getting Your Deposit Back
Section 9.11. Don''''t Look Inside the Box
Section 9.12. Faster Getters and Setters
Section 9.13. Getters That Double as Setters
Section 9.14. Restricting a Method to Class-Only or Instance-Only
Section 9.15. Exercise
Chapter 10. Object Destruction
Section 10.1. Nested Object Destruction
Section 10.2. Beating a Dead Horse
Section 10.3. Indirect Object Notation
Section 10.4. Additional Instance Variables in Subclasses
Section 10.5. Using Class Variables
Section 10.6. Weakening the Argument
Section 10.7. Exercise
Chapter 11. Some Advanced Object Topics
Section 11.1. UNIVERSAL Methods
Section 11.2. Testing Your Objects for Good Behavior
Section 11.3. AUTOLOAD as a Last Resort
Section 11.4. Using AUTOLOAD for Accessors
Section 11.5. Creating Getters and Setters More Easily
Section 11.6. Multiple Inheritance
Section 11.7. References to Filehandles
Section 11.8. Exercise
Chapter 12. Using Modules
Section 12.1. Sample Function-Oriented Interface: File::Basename
Section 12.2. Selecting What to Import
Section 12.3. Sample Object-Oriented Interface: File::Spec
Section 12.4. A More Typical Object-Oriented Module: Math::BigInt
Section 12.5. The Differences Between OO and Non-OO Modules
Section 12.6. What use Is Doing
Section 12.7. Setting the Path at the Right Time
Section 12.8. Importing with Exporter
Section 12.9. @EXPORT and @EXPORT_OK
Section 12.10. Exporting in a Primarily OO Module
Section 12.11. Custom Import Routines
Section 12.12. Exercise
Chapter 13. Writing a Distribution
Section 13.1. Starting with h2xs
Section 13.2. Looking at the Templates
Section 13.3. The Prototype Module Itself
Section 13.4. Embedded Documentation
Section 13.5. Controlling the Distribution with Makefile.PL
Section 13.6. Alternate Installation Locations (PREFIX=...)
Section 13.7. Trivial make test
Section 13.8. Trivial make install
Section 13.9. Trivial make dist
Section 13.10. Using the Alternate Library Location
Section 13.11. Exercise
Chapter 14. Essential Testing
Section 14.1. What the Test Harness Does
Section 14.2. Writing Tests with Test::Simple
Section 14.3. Writing Tests with Test::More
Section 14.4. Conditional Tests
Section 14.5. More Complex Tests (Multiple Test Scripts)
Section 14.6. Testing Things That Write to STDOUT and STDERR
Section 14.7. Exercise
Chapter 15. Contributing to CPAN
Section 15.1. The Comprehensive Perl Archive Network
Section 15.2. Getting Prepared
Section 15.3. Preparing Your Distribution
Section 15.4. Uploading Your Distribution
Section 15.5. Announcing the Module
Section 15.6. Testing on Multiple Platforms
Section 15.7. Consider Writing an Article or Giving a Talk
Section 15.8. Exercise
Appendix A. Answers to Exercises
Section A.1. Answers for Chapter 2
Section A.2. Answers for Chapter 3
Section A.3. Answers for Chapter 4
Section A.4. Answers for Chapter 5
Section A.5. Answer for Chapter 6
Section A.6. Answers for Chapter 7
Section A.7. Answers for Chapter 8
Section A.8. Answer for Chapter 9
Section A.9. Answer for Chapter 10
Section A.10. Answer for Chapter 11
Section A.11. Answer for Chapter 12
Section A.12. Answers for Chapters 13-15
Colophon
Index