1583334251300f8ab85950b9f12d4a35c26f39b5
[gitmo/moose-presentations.git] / moose-class / exercises / t / 06-advanced-attributes.t
1 # Your tasks ...
2 #
3 # First, you must make the account associated with a Person a proper
4 # class of its own. 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 of
14 # Int's. This should default to an empty array reference. Use a Native
15 # delegation method to push values onto this attribute.
16 #
17 # Use a trigger to record the _old value_ of the balance each time it
18 # changes. This means your trigger should not do anything if it is not passed
19 # an old value (this will be the case when the attribute is set for the first
20 # time). You can check for the presence of an old value by looking at the
21 # number of elements passed to the trigger in the @_ array.
22 #
23 # Now you can delete the HasAccount role entirely. Instead, add an "account"
24 # attribute to Person directly.
25 #
26 # This new account attribute should default to a new BankAccount object. Use
27 # delegation so that when the code calls Person->deposit and Person->withdraw,
28 # it calls those methods on the person's BankAccount object.
29 #
30 # Add a BUILD method to the Person class to set the owner of the
31 # Person's bank account to $self.
32
33 use strict;
34 use warnings;
35
36 use lib 't/lib';
37
38 use MooseClass::Tests;
39
40 MooseClass::Tests::tests06();