X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fexercises%2Ft%2F06-advanced-attributes.t;h=1583334251300f8ab85950b9f12d4a35c26f39b5;hb=0f1b9555cfda7afaaf652f1a9eef2d8fa89257a9;hp=138ef261acf94fbcbe5b7fd016d4224ef3723aa7;hpb=1338bcf1a5053338be1bc023fd52004576ee92d8;p=gitmo%2Fmoose-presentations.git diff --git a/moose-class/exercises/t/06-advanced-attributes.t b/moose-class/exercises/t/06-advanced-attributes.t index 138ef26..1583334 100644 --- a/moose-class/exercises/t/06-advanced-attributes.t +++ b/moose-class/exercises/t/06-advanced-attributes.t @@ -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. @@ -10,25 +10,22 @@ # # 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();