Commit | Line | Data |
66b226e5 |
1 | # Your tasks ... |
2 | # |
3 | # First, we want to make the account associated with a Person a proper |
4 | # class. Call it BankAccount. |
5 | # |
6 | # This class should have two attributes, "balance", an Int that |
7 | # defaults to 100, and "owner", a Person object. |
8 | # |
9 | # The owner attribute should be a weak reference to prevent cycles. |
10 | # |
11 | # Copy the deposit and withdraw methods from the HasAccount role. |
12 | # |
13 | # Finally, add a read-only history attribute. This will be an ArrayRef |
14 | # of Int's. This should default to an empty array reference. |
15 | # |
16 | # Use a trigger to record the _difference_ after each change to the |
17 | # balance. The previous balance is the sum of all the previous |
18 | # changes. You can use List::Util's sum function to calculate this. To |
19 | # avoid warnings the first time history is recorded, default to 0 if |
20 | # history is empty. |
21 | # |
22 | # Use a BUILD method in BankAccount to record the original balance in |
23 | # the history. |
24 | # |
25 | # We will now delete the HasAccount role entirely. Instead, add an |
26 | # "account" attribute to Person directly. |
27 | # |
28 | # This new account attribute should default to a new BankAccount |
29 | # object. Use delegation so that we can call Person->deposit and |
30 | # Person->withdraw and have it call those methods on the person's |
31 | # BankAccount object. |
32 | # |
33 | # Add a BUILD method to the Person class to set the owner of the |
34 | # Person's bank account to $self. |
35 | |
36 | use strict; |
37 | use warnings; |
38 | |
39 | use lib 't/lib'; |
40 | |
41 | use MooseClass::Tests; |
42 | |
43 | use Person; |
44 | use Employee; |
45 | |
46 | MooseClass::Tests::tests06(); |