Clarify how to check whether old value is passed to a trigger
[gitmo/moose-presentations.git] / moose-class / exercises / t / 06-advanced-attributes.t
index 138ef26..1583334 100644 (file)
@@ -1,7 +1,7 @@
 # Your tasks ...
 #
-# First, we want to make the account associated with a Person a proper
-# class. Call it BankAccount.
+# First, you must make the account associated with a Person a proper
+# class of its own. Call it BankAccount.
 #
 # This class should have two attributes, "balance", an Int that
 # defaults to 100, and "owner", a Person object.
 #
 # Copy the deposit and withdraw methods from the HasAccount role.
 #
-# Finally, add a read-only history attribute. This will be an ArrayRef
-# of Int's. This should default to an empty array reference.
+# Finally, add a read-only history attribute. This will be an ArrayRef of
+# Int's. This should default to an empty array reference. Use a Native
+# delegation method to push values onto this attribute.
 #
-# Use a trigger to record the _difference_ after each change to the
-# balance. The previous balance is the sum of all the previous
-# changes. You can use List::Util's sum function to calculate this. To
-# avoid warnings the first time history is recorded, default to 0 if
-# history is empty.
+# Use a trigger to record the _old value_ of the balance each time it
+# changes. This means your trigger should not do anything if it is not passed
+# an old value (this will be the case when the attribute is set for the first
+# time). You can check for the presence of an old value by looking at the
+# number of elements passed to the trigger in the @_ array.
 #
-# Use a BUILD method in BankAccount to record the original balance in
-# the history.
+# Now you can delete the HasAccount role entirely. Instead, add an "account"
+# attribute to Person directly.
 #
-# We will now delete the HasAccount role entirely. Instead, add an
-# "account" attribute to Person directly.
-#
-# This new account attribute should default to a new BankAccount
-# object. Use delegation so that we can call Person->deposit and
-# Person->withdraw and have it call those methods on the person's
-# BankAccount object.
+# This new account attribute should default to a new BankAccount object. Use
+# delegation so that when the code calls Person->deposit and Person->withdraw,
+# it calls those methods on the person's BankAccount object.
 #
 # Add a BUILD method to the Person class to set the owner of the
 # Person's bank account to $self.
@@ -40,8 +37,4 @@ use lib 't/lib';
 
 use MooseClass::Tests;
 
-use Person;
-use Employee;
-use BankAccount;
-
 MooseClass::Tests::tests06();