Skip to Content
Perl Cookbook, 2nd Edition
book

Perl Cookbook, 2nd Edition

by Tom Christiansen, Nathan Torkington
August 2003
Intermediate to advanced content levelIntermediate to advanced
964 pages
23h 24m
English
O'Reilly Media, Inc.
Content preview from Perl Cookbook, 2nd Edition

Chapter 13. Classes, Objects, and Ties

All the world over, I will back the masses against the classes.

William E. Gladstone, Speech at Liverpool, 28 June 1886

Introduction

Although Perl was not initially conceived of as an object-oriented language, within a few years of its initial release, complete support for object-oriented programming had been added. As usual, Perl doesn’t try to enforce one true style, but embraces many. This helps more people do their job the way they want to do it.

You don’t have to use objects to write programs, unlike Java, where programs are instances of objects. If you want to, though, you can write Perl programs that use nearly every weapon in the object-oriented arsenal. Perl supports classes and objects, single and multiple inheritance, instance methods and class methods, access to overridden methods, constructors and destructors, operator overloading, proxy methods through autoloading, delegation, a rooted hierarchy for all objects, and two levels of garbage collection.

You can use as many or as few object-oriented techniques as you want and need. Ties are the only part of Perl where you must use object orientation. And even then, only the module implementor need be aware of this; the casual user gets to remain blissfully unaware of the internal mechanics. Ties, discussed in Recipe 13.15, let you transparently intercept access to a variable. For example, you can use ties to create hashes that support lookups by key or value instead of just by key.

Under ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Cookbook

Perl Cookbook

Tom Christiansen, Nathan Torkington
Programming Perl, 3rd Edition

Programming Perl, 3rd Edition

Larry Wall, Tom Christiansen, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant

Publisher Resources

ISBN: 0596003137Supplemental ContentErrata Page