Moose-0.93

NAME

Moose::Manual::Unsweetened - Moose idioms in plain old Perl 5 without the sugar

DESCRIPTION

If you're trying to figure out just what the heck Moose does, and how it saves you time, you might find it helpful to see what Moose is really doing for you. This document shows you the translation from Moose sugar back to plain old Perl 5.

Wow, that was a mouthful! One thing to note is just how much space the data validation code consumes. As a result, it's pretty common for Perl 5 programmers to just not bother. Unfortunately, not validating arguments leads to surprises down the line ("why is birth_date an email address?").

Also, did you spot the (intentional) bug?

It's in the _validate_birth_date() method. We should check that the value in $birth_date is actually defined and an object before we go and call isa() on it! Leaving out those checks means our data validation code could actually cause our program to die. Oops.

Note that if we add a superclass to Person we'll have to change the constructor to account for that.

(As an aside, getting all the little details of what Moose does for you just right in this example was really not easy, which emphasizes the point of the example. Moose saves you a lot of work!)

Then we could define a base class that would accept such a definition, and do the right thing. Keep that sort of thing up and we're well on our way to writing a half-assed version of Moose!

Of course, there are CPAN modules that do some of what Moose does, like Class::Accessor, Class::Meta, and so on. But none of them put together all of Moose's features along with a layer of declarative sugar, nor are these other modules designed for extensibility in the same way as Moose. With Moose, it's easy to write a MooseX module to replace or extend a piece of built-in functionality.

Moose is a complete OO package in and of itself, and is part of a rich ecosystem of extensions. It also has an enthusiastic community of users, and is being actively maintained and developed.