Fix lie in the docs (error_class does to have a default)
[gitmo/Moose.git] / lib / Moose / Unsweetened.pod
index 654e522..8f2b5be 100644 (file)
@@ -41,8 +41,10 @@ First, we define two very small classes the Moose way.
       => via { $en_parser->parse_datetime($_) };
 
   has birth_date => (
-      is  => 'rw',
-      isa => 'DateTime',
+      is      => 'rw',
+      isa     => 'DateTime',
+      coerce  => 1,
+      handles => { birth_year => 'year' },
   );
 
   subtype 'ShirtSize'
@@ -195,6 +197,12 @@ helpers like C<Class::Accessor>.
       return $self->{birth_date};
   }
 
+  sub birth_year {
+      my $self = shift;
+
+      return $self->birth_date->year;
+  }
+
   sub shirt_size {
       my $self = shift;
 
@@ -211,19 +219,13 @@ data validation code consumes. As a result, it's pretty common for
 Perl 5 programmers to just not bother, which results in much more
 fragile code.
 
-Did you spot the bug?
+Did you spot the (intentional) bug?
 
 It's in the C<_validate_birth_date()> method. We should check that
 that value in C<$birth_date> is actually defined and object before we
 go and call C<isa()> on it! Leaving out those checks means our data
 validation code could actually cause our program to die. Oops.
 
-There's one bit of code in there worth explaining, which is the
-handling of the birth date for coercion. In both the constructor and
-accessor, we first take a copy of the birth date before passing it to
-the coercion routine. This is to avoid changing the value as it was
-passed to those methods, which could cause problems for the caller.
-
 Also note that if we add a superclass to Person we'll have to change
 the constructor to account for that.
 
@@ -314,7 +316,9 @@ our way to writing a half-assed version of Moose!
 Of course, there are CPAN modules that do some of what Moose does,
 like C<Class::Accessor>, C<Class::Meta>, and so on. But none of them
 put together all of Moose's features along with a layer of declarative
-sugar.
+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.
 
 =head1 AUTHOR