Chapter 13
Moose
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Understanding Moose Syntax including attributes, constructors, and inheritance
- Using Type constraints, Method modifiers, roles, and popular Moose extensions
- Understanding Moose Best Practices
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_13_1_person.pl
- example_13_2_episode.pl
- lib/Person.pm
- lib/My/Company/Moose/Types.pm
- lib/TV/Episode.pm
- lib/TV/Episode/Broadcast.pm
- listing_13_1_age.pl
In the beginning there was Perl and on the fifth version Larry blessed references and said, “Let there be objects” and all was good.
Well, sort of. Chapter 12 showed how to create objects with Perl’s builtin bless syntax, but there’s a lot of tedium in validating that your data is correct and setting up your classes properly. If you’re familiar with object-oriented programming (OOP) in other languages, you may have found Perl’s implementation to be a bit crufty. You’d be right.
To work around Perl’s rather simple object facilities, many programmers have taken a swing at making it easier to write objects. There is Class::MakeMethods, Class::MethodMaker, Class::BuildMethods, Class::Accessor, Object::Tiny, and so on. As of this writing, there are approximately 500 different packages in the Class:: and Object:: namespaces, many of which aren’t ...
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.