Explain attributes and subclassing
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe2.pod
index 04c5613..bbd4788 100644 (file)
@@ -3,13 +3,11 @@
 
 =head1 NAME
 
-Moose::Cookbook::Recipe2 - A simple Bank Account example
+Moose::Cookbook::Recipe2 - A simple B<BankAccount> example
 
 =head1 SYNOPSIS
 
   package BankAccount;
-  use strict;
-  use warnings;
   use Moose;
   
   has 'balance' => (isa => 'Int', is => 'rw', default => 0);
@@ -28,8 +26,6 @@ Moose::Cookbook::Recipe2 - A simple Bank Account example
   }
   
   package CheckingAccount;
-  use strict;
-  use warnings;        
   use Moose;
   
   extends 'BankAccount';
@@ -39,7 +35,7 @@ Moose::Cookbook::Recipe2 - A simple Bank Account example
   before 'withdraw' => sub {
       my ($self, $amount) = @_;
       my $overdraft_amount = $amount - $self->balance();
-      if (self->overdraft_account && $overdraft_amount > 0) {
+      if ($self->overdraft_account && $overdraft_amount > 0) {
           $self->overdraft_account->withdraw($overdraft_amount);
           $self->deposit($overdraft_amount);
       }
@@ -68,10 +64,10 @@ new attribute feature, that of a default value.
 
   has 'balance' => (isa => 'Int', is => 'rw', default => 0);
 
-This tells is that a B<BankAccount> has a C<balance> attribute, 
-which is has the C<Int> type constraint, a read/write accessor, 
+This tells us that a B<BankAccount> has a C<balance> attribute, 
+which has the C<Int> type constraint, a read/write accessor, 
 and a default value of C<0>. This means that every instance of 
-B<BankAccount> that is created will have it's C<balance> slot 
+B<BankAccount> that is created will have its C<balance> slot 
 initialized to C<0>. Very simple really :)
 
 Next come the methods. The C<deposit> and C<withdraw> methods 
@@ -95,7 +91,7 @@ you define, a corresponding type constraint will be created for
 that class. This means that in the first recipe, a C<Point> and 
 C<Point3D> type constraint were created, and in this recipe, both 
 a C<BankAccount> and a C<CheckingAccount> type constraint were 
-created. Moose does this as a convience for you so that your 
+created. Moose does this as a convenience for you so that your 
 class model and the type constraint model can both be kept in 
 sync with one another. In short, Moose makes sure that it will 
 just DWIM (1).
@@ -107,7 +103,7 @@ modifier.
   before 'withdraw' => sub {
       my ($self, $amount) = @_;
       my $overdraft_amount = $amount - $self->balance();
-      if (self->overdraft_account && $overdraft_amount > 0) {
+      if ($self->overdraft_account && $overdraft_amount > 0) {
           $self->overdraft_account->withdraw($overdraft_amount);
           $self->deposit($overdraft_amount);
       }
@@ -130,7 +126,7 @@ pseudo-package. So the above method is equivalent to the one here.
   sub withdraw {
       my ($self, $amount) = @_;
       my $overdraft_amount = $amount - $self->balance();
-      if ($overdraft_amount > 0 && $self->overdraft_account) {
+      if ($self->overdraft_account && $overdraft_amount > 0) {
           $self->overdraft_account->withdraw($overdraft_amount);
           $self->deposit($overdraft_amount);
       }
@@ -142,13 +138,13 @@ author of the B<BankAccount> subclass does not need to remember
 to call C<SUPER::withdraw> and to pass it the C<$amount> argument. 
 Instead the method modifier assures that all arguments make it 
 to the superclass method correctly. But this is actually more 
-than just a convience for forgetful programmers, it also helps 
+than just a convenience for forgetful programmers, it also helps 
 isolate subclasses from changes in the superclasses. For instance, 
 if B<BankAccount::withdraw> were to add an additional argument 
 of some kind, the version of B<CheckingAccount::withdraw> which 
 uses C<SUPER::withdraw> would not pass that extra argument 
-correctly. Whereas the method modifier version of would pass 
-all arguments along correctly automatically.
+correctly. Whereas the method modifier version would automatically pass 
+along all arguments correctly.
 
 Just as with the first recipe, object instantiation is a fairly 
 normal process, here is an example:
@@ -160,7 +156,7 @@ normal process, here is an example:
                                             );
 
 And as with the first recipe, a more in-depth example of using 
-these classes can be found in the F<t/002_basic.t> test file.
+these classes can be found in the F<t/002_recipe.t> test file.
 
 =head1 CONCLUSION
 
@@ -207,11 +203,11 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2006, 2007 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
-=cut
\ No newline at end of file
+=cut