Chapter 12
Object Oriented Perl
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Understanding what an object is
- Learning the three rules of Perl’s OO system
- Creating a class
- How to subclass a class
- Overloading classes
- Learning OO traps for the unwary
WROX.COM CODE DOWNLOAD FOR THIS CHAPTER
The wrox.com code downloads for this chapter are found at http://www.wrox.com/remtitle.cgi?isbn=1118013847 on the Download Code tab. The code for this chapter is divided into the following major examples:
- example_12_1_shopper.pl
- example_12_2_episode.pl
- lib/Shopper/Personal.pm
- lib/TV/Episode.pm
- lib/TV/Episode/Broadcast.pm
- lib/TV/Episode/OnDemand.pm
- lib/TV/Episode/Version.pm
- listing_12_1_episode.pl
Chapter 10 mentioned that knowledge of the sort, map, and grep functions is sort of a litmus test that some programmers use to know if a Perl developer is at least at an intermediate level. Knowledge of object-oriented programming (often referred to as OOP, or just OO) is your first step toward being an advanced Perl developer. Many languages support OO programming, and learning about it in Perl will help you in many other languages.
Two chapters discuss OOP. This chapter describes Perl’s built-in OO tools. They’re minimal, but this minimalism gives you a lot of freedom. You need to understand how Perl’s built-in OO works because much of the Perl software in the wild is written with this.
The next chapter, Chapter 13, covers Moose which is an incredibly powerful object system built on top of Perl’s OO tools. ...
Get Beginning Perl now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.