Object Oriented Perl

( 1 )

Overview

Techniques and tricks to master basic and advanced OO Perl for programmers who already have basic to intermediate skills in procedural Perl.

Programmers who already have basic to intermediate skills in procedural Perl and understand fundamental concepts of object orientation will get a solid understanding of basic and advanced object-oriented Perl. This book clarifies when, where and why to use Perl. Featuring many techniques and tricks, it presents solutions to ...

See more details below
Paperback (New Edition)
$31.74
BN.com price
(Save 26%)$42.95 List Price
Other sellers (Paperback)
  • All (21) from $1.99   
  • Used (21) from $1.99   
Sending request ...

Overview

Techniques and tricks to master basic and advanced OO Perl for programmers who already have basic to intermediate skills in procedural Perl.

Programmers who already have basic to intermediate skills in procedural Perl and understand fundamental concepts of object orientation will get a solid understanding of basic and advanced object-oriented Perl. This book clarifies when, where and why to use Perl. Featuring many techniques and tricks, it presents solutions to common programming problem and explains how to combine Perl and C++.

Read More Show Less

Editorial Reviews

Booknews
Conway computer science, Monash U., Melbourne provides novices and experienced Perl hackers alike with a guide to writing clean, readable, and maintainable Perl programs. The book begins with object orientation and Perl basics, and moves on to topics such as encapsulation, polymorphism, operator overloading, multiple dispatch and persistence. Conway incorporates examples of databases, pattern matching, multiprocessing, encryption, and debugging among others, and he includes transition guides from C++, Java, Eiffel, and Smalltalk. Annotation c. Book News, Inc., Portland, OR booknews.com
Slashdot.org
...a gem of a book...Superbly organized and excellently explained, this is the definitive book on Object Oriented programming with Perl. Judging from the comments of more qualified experts, we agree that this book belongs on the shelf of any serious Perl hacker.
Development Exchange
Object Oriented Perl is well written and communicates a lot of technical know-how to its readers, both in terms of specific language features and general design concepts. You'll put this book down with more knowledge of modular Perl than you had when you picked it up. Whether object-oriented Perl programming is right for your projects is another question-but there's no better decision helper than Conway's guide.
Read More Show Less

Product Details

  • ISBN-13: 9781884777790
  • Publisher: Manning Publications Company
  • Publication date: 1/28/2000
  • Edition description: New Edition
  • Edition number: 1
  • Pages: 490
  • Sales rank: 1,410,769
  • Product dimensions: 7.42 (w) x 9.22 (h) x 1.17 (d)

Meet the Author

Dr. Damian Conway is a Senior Lecturer in Computer Science and Software Engineering at Monash University (Melbourne, Australia), where he teaches object-oriented software engineering. He is an effective teacher, an accomplished writer, and the author of several popular Perl modules. He is also a semi-regular contributor to the Perl Journal. In 1998 he was the winner of the Larry Wall Award for Practical Utility for two modules (Getopt::Declare and Lingua::EN::Inflect) and in 1999 he won his second "Larry" for his Coy.pm haiku-generation module.

Schwartz owns & operates Stonehenge Consulting Services

Read More Show Less

Table of Contents


  1. Introduction
    1. What is this book about?
    2. What is object-oriented Perl?
    3. Whom this book is for?
    4. Where to find what you're looking for?

  2. What You Need To Know First (An OO Primer)
    1. The essential elements of OO
      • Abstraction
      • Encapsulation
      • Inheritance
      • Polymorphism
    2. Other OO concepts
      • Genericity
      • Interface vs implementation
      • Class vs type
      • Persistence
    3. A few words about terminology
    4. Where to find out more

  3. What You Need To Know Second (A Perl Refresher)
    1. Essential Perl
      • Scalars
      • Arrays
      • Hashes
      • Subroutines
      • References
      • Packages
    2. Non-essential (but very useful) Perl
      • Modules
      • Autoloading
      • Closures
      • Typeglobs
    3. Where to find out more
      • Books
      • The Perl documentation
      • The Perl Journal
      • Perl on the WWW
      • Newsgroups

  4. Simple Object-Oriented Perl
    1. Three little rules
      • Rule 1: To create a class, build a package
      • Rule 2: To create a method, write a subroutine
      • Rule 3: To create an object, bless a referent
    2. A simple Perl class
      • The code
      • Using the CD::Music class
    3. Making life easier
      • Class modules
      • use strict and the -w flag
      • Automating data member access
      • Documenting a class
    4. Creation and destruction of objects
      • Constructors
      • Destructors
    5. The CD::Music class, compleat

  5. Blessing Variables
    1. What's wrong with a hash?
    2. Blessing an array
      • Reimplementing CD::Music
      • An array-specific example - iterators
      • Where to find out more
    3. Blessing a pseudo-hash
      • A pseudo-what???
      • Limitations of a pseudo-hash
      • Advantages of a pseudo-hash
      • The worst of both worlds?
      • Compile-time support for run-time performance
      • Just how Perl knows at compile-time that a particular
      • Yet another version of CD::Music
      • Where to find out more
    4. Blessing a scalar
      • Why not bless a scalar?
      • An object-oriented password
      • A bit-string class
      • Where to find out more

  6. Blessing Other Things
    1. Blessing a regular expression
      • The qr operator
      • Why an OO regular expression class?
      • Designing a different regular expressions mechanism
      • A closer look at the two classes
      • On the separation of Search and State
      • Where to find out more
    2. Blessing a subroutine
      • So how can a subroutine be an object?
      • Why objectify a subroutine?
      • A lexer object
      • Example: A simple pretty-printer
      • Where to find out more
    3. Blessing a typeglob
      • Paging STDOUT
      • A multiprocess pager class
      • A threaded pager class
      • Where to find out more

  7. Inheritance
    1. How Perl handles inheritance
      • The @ISA array
      • What inheritance means in Perl
      • Where the call goes
      • Constructors and inheritance
      • Destructors and inheritance
    2. Tricks and Traps
      • Naming attributes of derived classes
      • The isa() subroutine
      • The can() subroutine
      • The UNIVERSAL package
      • The SUPER pseudo-package
      • Inheritance and pseudo-hashes
      • Issues related to accessing class data
    3. Example: Inheriting the CD class
      • Applied laziness
      • Class attributes revisited
      • An alternative solution

  8. Polymorphism
    1. Polymorphism in Perl
    2. Example: Polymorphic methods for the Lexer class
    3. The simple pretty-printer objectified
    4. Using interface polymorphism instead

  9. Automating class creation
    1. The Class::Struct module
    2. The Class::MethodMaker module

  10. Operator Overloading
    1. The prob
Read More Show Less

Preface

This book is about the Laziness, on a grand scale.

It's about how to create larger, more robust applications that require less effort to built, less time to debug, fewer resources to maintain, and less trouble to extend.

Specifically, it's about how to do all that with the object-oriented features of Perl--how those features work, and how to make use of the many labor-saving techniques and "tricks" that they make possible. Presenting these new language features requires only a few chapters in total, but the range of programming styles and idioms those extra features make available would fill several books this size. This one tries to concentrate on the most useful and powerful ones.

This book is also about the tremendous flexibility of Perl's approach to object orientation, and how, in Perl, there's almost always more than one object-oriented way to solve a given problem. You'll find that the text revisits a few key examples time and again, extending and reimplementing them in various ways. Sometimes those changes will add extra functionality to a previous example, sometimes they'll merely illustrate an alternative solution (with different strengths and limitations).

This book is about developing programming skills that scale. Perl is a great language for "one-line-stands"--ad hoc solutions that are quick, cryptic, and unstructured. But Perl can also be a great language for developing large and complex applications. The only problem is that while "quick, cryptic, and unstructured" is cute in a throw-away script, it's not so amusing in a 5,000 or 50,000 lines of application code.Object-oriented programming techniques can help to solve the problem of building large, maintainable, reusable, and comprehensible systems in Perl.

Above all, this book is about how Perl makes object-oriented programming enjoyable, and how object-oriented programming makes Perl even more so. Life is too short to endure the cultured bondage-and-discipline of Eiffel programming, or to wrestle the alligators that lurk in the muddy semantics of C++. Object-oriented Perl gives you all the power of those languages (and more!), but very few of their tribulations. And best of all, like regular Perl, it's fun!

Who's this book for?

This book was written for the whole Perl community. In other words, for an eclectic range of people of wildly differing backgrounds, interests, and levels of experience.

To that end, it starts slowly, assuming only a very basic familiarity with the core features of Perl itself: scalars, arrays and hashes, pattern matching, basic I/O, and simple subroutines. If these things sound familiar, this book is definitely for you. If they don't, Chapter 2 provides a quicker refresher course in everything you'll need to know.

The only other assumption that's made is that you're interested in object orientation. Maybe you've only heard about its many advantages. Maybe you're familiar with the basic concepts (if not, see Chapter 1). Maybe you've already had some experience--even a bad one!--in another object-oriented language. If so, you might find Appendix B a useful place to start.

If you've already dabbled in object-oriented Perl--perhaps blessed a hash or two--this book is also for you. If you start at Chapter 4, you'll find a range of increasingly specialized techniques that will expand your repertoire and maybe even challenge some of your notions about object-oriented programming.

If you're an experienced object-oriented Perl programmer, this book's for you too. The earlier chapters might contain a few tricks you haven't seen before (blessed a regular expression or a typeglob lately?), and the later chapters may suggest some novel approaches you haven't considered before (for example, the section on generic trees in Chapter 12 is well worth a look).

Even if you're a Perl guru, this book's still for you. Check out Chapter 7, where object methods that don't have a class are called on class objects that don't have a method. Or try Chapter 11, where objects are stored as one of their own attributes. Or explore Chapter 13, where the entire dispatch mechanism is replaced with one that provides multiply dispatched methods and subroutine overloading.

What is object-oriented Perl?

Object-oriented Perl is a small amount of additional syntax and semantics, added to the existing imperative features of the language. Those extras allow regular Perl packages, variables, and subroutines to behave like classes, objects, and methods.

It's also a small number of special variables, packages and modules, and a large number of new techniques, that together provide inheritance, data encapsulation, operator overloading, automated definition of commonly used methods, generic programming, multiply-dispatched polymorphism, and persistence.

It's an idiosyncratic, no-nonsense, demystified approach to object-oriented programming, with a typical disregard for the accepted rules and conventions. It draws inspiration (and sometimes syntax) from many different object-oriented predecessors, adapting their ideas to its own needs. It reuses and extends the functionality of existing Perl features, and in the process throws an entirely new slant on what they mean.

In other words, it's everything that regular Perl is, only object-oriented.

What object-oriented Perl isn't.

Perl was not originally designed--or implemented--as an object-oriented language. Its version of object orientation is simple and well integrated, but it's not fundamental to the language.

That evolutionary development still shows in the few places where object-oriented features of the language are still experimental or incomplete. For example, recent versions of the Perl compiler support weakly-typed variables, which provide some level of run-time checking and optimization for accesses to the data stored Perl objects. But the current version of the mechanism, and its two support modules, don't actually enforce type safety or proper data encapsulation, and they don't fully support inheritance.

Because Perl wasn't originally designed as an object-oriented language, the other thing that object-oriented Perl isn't, is fast. Calling a method through an object is significantly slower than calling a regular Perl subroutine. Just how much slower is a matter of some debate, and depends on whether you measure entire systems or just raw single-call invocation speed.

A single method call is about 30% slower than a regular call to the same subroutine (depending on your hardware, operating system, the phase of the moon, etc.) That's because, before it can call the appropriate subroutine, a method call has to work out the class of the object on which the method was invoked, so it knows which method to use (see Chapters 3 and 6). In contrast, a regular call has no choice to make--it just jumps straight into the subroutine you specified. That's always going to be faster.

Though they're individually much slower, method calls are also more powerful than regular subroutine calls, due to a feature known as polymorphism (see Chapters 1 and 7). In a larger system that redresses the speed imbalance in a little, but in general it's fair to say that an object-oriented implementation of a system in Perl will almost never be faster than the equivalent non-object-oriented implementation, and will usually be somewhere between 20 to 50 percent slower.

Those figures are enough to turn many people away from object-oriented Perl, and that's a pity because then they miss out on the many compensating benefits of object-oriented design and implementation: simpler analysis methods, a domain-oriented approach to design, cleaner and more compact code, more robust implementations, greater code modularity, easier debugging, easier maintenance, more comprehensible interfaces to modules (including operator-based interfaces), better abstraction of software components, less namespace pollution, greater code reusability, greater scalability of software, and better marketability of the final product.

The sad thing is that people get spooked by the numbers (20 to 50 percent slower!!!) and forget what that really means (.just as fast in six months time, when processor speeds have doubled).

Where to find what you're looking for

This book is arranged as a tutorial on the various object-oriented features of Perl, and the many techniques that have been developed for using those features.

Chapter 1 provides a quick revision of the fundamentals of object orientation: objects, classes, attributes, methods, inheritance, polymorphism, aggregation, interfaces, genericity, and persistence. Chapter 2 offers a refresher on various aspects of the Perl language that are most relevant to object-oriented Perl: basic data types, subroutines and closures, references, packages and modules, typeglobs, and the CPAN.

Chapter 3 introduces the basic features of Perl's object-oriented mechanisms, concentrating on the most commonly used way of building classes and objects. Chapters 4 and 5 explore the numerous other ways of implementing objects in Perl. Chapter 6 introduces Perl's inheritance mechanism and Chapter 7 discusses Perl's approach to polymorphism.

Chapter 8 describes two freely available packages that can be used to automate the creation of class methods and attributes. Chapter 9 describes the Perl tie mechanism, which allows objects to be accessed like regular Perl variables or filehandles. This theme is continued in Chapter 10, where Perl operator overloading facilities are introduced.

Chapter 11 looks at the problem of Perl's poor support for encapsulation, and suggests three class implementation techniques that can be used to protect attributes within objects. Chapter 12 explains why generic programming techniques are rarely needed in Perl, and suggests several useful approaches for the few situations where they are required.

Chapter 13 looks at a generalized form of polymorphism known as multiple dispatch, which allows every argument of a method call to contribute to the invocation process. Chapter 14 examines how persistence techniques can be integrated with an object-oriented system.

Appendix A provides a condensed summary of Perl's object-oriented features, with examples of the syntax related for each. Appendix B provides an overview of those same features designed to assist programmers who are already familiar with one of four major object-oriented languages: Smalktalk, C++, Java, and Eiffel. A glossary of important object-oriented terms is also provided.

Throughout the text, each feature and technique is introduced with an example of a common type of programming problem that the feature or technique helps to solve. If you're looking for a specific technique to solve a particular problem, here's a list of the example problems, and the chapter and section in which they're discussed. The words "(and following)" indicate a major example that continues in subsequent sections of the same chapter.

Bit-strings

Chapter 4: A bit-string class

Chapter 6: The "empty subclass" test

Bugs: storing reports

Chapter 3: Three little rules

Chapter 8: Creating classes (and following)

Case insensitive hashes

Chapter 9: Case-insensitive hashes

CDs: storing catalog information

Chapter 3: A simple class (and following)

Chapter 4: Reimplementing CD::Music (and following)

Chapter 6: Inheriting the CD::Music class

Chapter 8: Automating the CD::Music class (and following)

Chemical vs medical names

Chapter 11: Ambiguous keys in a securehash

Colours: RGB represention

Chapter 11: Converting to "fast" mode (and following)

Contacts data

Chapter 14: Class specific persistence (and following)

Days of the week

Chapter 10: Fallback operations (and following)

Debugging: tracking the source of data

Chapter 9: Implementing a scalar using a non-scalar (and following)

EBCDIC: automated interconversion with ASCII

Chapter 9: Filtered filehandles

Employees: tracking and identifying

Chapter 8: Flag-like attributes (and following)

GDP: per capita, China vs USA

Chapter 10: The problem

Genetics: accessing and manipulating larger DNA databases

Chapter 9: A base/codon array (and following)

Graphical user interfaces: event handling

Chapter 13: What is multiple dispatch (and following)

Hashes: nested iterations of the same hash

Chapter 4: An array-specific example

Chapter 5: So how can a subroutine be an object?

Hashes: sorted keys

Chapter 9: Sorted hashes

Lexical analysis

Chapter 5: A lexer object

Chapter 7: Polymorphic methods for the Lexer class

Lists: generic

Chapter 8: Subroutines as attributes

Chapter 12: Closures as generic subroutines

Networks: representation

Chapter 3: Destructors and circular data structures

Paged output

Chapter 5: Paging STDOUT (and following)

Passwords

Chapter 4: An object-oriented password

Chapter 8: Key-like attributes

Personality traits: statistical analysis

Chapter 8: Hash attributes

Pretty-printing

Chapter 5: A simple pretty-printer

Chapter 7: The simple pretty-printer objectified (and following)

Queues: implementing a customer queue

Chapter 8: List attributes

Regular expressions: making them more readable

Chapter 5: Blessing a regular expression (and following)

Roman numerals

Chapter 10: A Roman numerals class (and following)

Round pegs in square holes

Chapter 13: Handling dispatch resolution failure

Semaphores: control of a transceiver

Chapter 4: Advantages of a pseudo-hash (and following)

Chapter 6: Inheritance and pseudo-hashes

Soldiers: dog-tag information

Chapter 8: Key-like attributes

Chapter 11: Encapsulation via closures (and following)

Stringification: of simple and hierarchical data types

Chapter 13 Non-class types as parameters (and following)

Chapter 14: Encoding/serialization

Taxonomies

Chapter 6: Constructors and inheritance (and following)

Trees: generic binary search trees and heaps

Chapter 12: The generic Tree class (and following)

Unique IDs: autoincremented scalar variables

Chapter 9: A simple example

Typographical conventions

The following typographical conventions are used throughout this book:

Technical terms (all of which are explained in the Glossary) are introduced in italics.

Code examples and fragments are set in a fixed-width font.

Comments in code are set in a fixed-width italic font.

Sections of code that are of special significance are set in a bold fixed-width font. Often these sections represent changes from a previous version of the code.

All forms of system-level text and anything you might actually type yourself--file names, command-line instructions, program input, URLs, and newgroup names--are set in a sans-serif font.

Any kind of program output, including exception and error messages, is set in a bold sans-serif font.

 

Acknowledgements

The small number of names on the cover of most textbooks--in this case, just one--is an outright deception. Every textbook is a collaboration of a large number of dedicated and talented people. In writing this book I have been guided, helped, and supported by a multitude of generous and wise people. I am especially grateful to.

My beloved Linda, who has borne most of the burden of our lives these past six months, and who still found time to contribute her wisdom and insight to this book. Every day she sustains me with her extraordinary beauty, grace, and love; she is my inspiration, my joy, and my light.

My parents, James and Sandra, for their faith, love, and very practical support over so many years. They have been the giants on whose shoulders I have stood.

My parents-in-law, Corallie and Fred, for their encouragement, their generosity, and their love over the past decade.

Larry Wall, for giving us all this wondrous adventure playground called Perl.

Nat Torkington, who has been a constant source of wise counsel, practical assistance, and a host of favors far beyond the call of friendship, duty, or even Antipodean solidarity.

Randal Schwartz who graciously found time in his insanely busy life to review large chunks of this book, and whose suggestions have improved it immeasurably.

Bennett Todd, whose excellent advice, unflagging enthusiasm, and endless encouragement, has buoyed me through some very dark hours.

Mark-Jason Dominus, whose insight and experience were instrumental in setting the overall structure and direction of my early drafts, and whose guidance I have sorely missed ever since.

The many other reviewers of my manuscripts, who have devoted extraordinary amounts of time, effort, and ability to dissecting my English and my Perl: Ilya Zakharevich for his excellent advice on the care and feeding of operators; Tim Bunce, François Désarménien, Brian Shensky, and Adrian Blakey, for knocking my SQL into shape; Gary Ashton-Jones, for highlighting the important of sequence; Leon Brocard, for keeping the focus where it ought to be; David Cantrell, for his tremendous attention to detail; and to John Dlugosz, for making me question so many assumptions.

The many other members of the Perl community who have shared their understanding with me, and helped to resolve all manner of finer points of Perl lore.

My colleagues at Monash University, for their support and encouragement. In particular: David Abramson, John Crossley, Trevor Dix, Linda McIver, Ann Nicholson, Steve Welsh, and Ingrid Zukerman.

Marjan Bace and the staff of Manning Publications, who have guided and encouraged me at every stage of development with patience, good humour, and very practical support: Brian Riley and Peter Schoenberg, who watched over me; Ted Kennedy, who masterminded the review process, adding his own invaluable suggestions; Ben Kovitz, for his guidance and advice on the material itself; Mary Piergies who turned the raw manuscript into a polished book; Leslie Haimes, who provided its oustanding "look-and-feel"; Syd Brown, who worked typesetting miracles.

Read More Show Less

Customer Reviews

Average Rating 2
( 1 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(1)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted February 5, 2000

    loaded with errors ...

    when i saw the glowing reviews from schwartz and christiansen on the back of the book, i figured it had to be something special. let me just say that mr. conway blew threw the perl primer (about the first 70 pages) so quickly and carelessly that i had to read it again. i found several coding errors in those first 70 pages alone. after that, i wasn't about to trust anything he said in the rest of the book, even if i COULD understand what he was talking about. if there's another object-oriented perl book out there, i need to find it NOW!!!

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)