+
+
+
Native Delegation - Array(Ref)
package Person;
use Moose;
@@ -3340,24 +3370,64 @@ has _favorite_numbers => (
-
Native Delegation - Counter
+
Native Delegation - Array(Ref)
+
+
my $person = Person->new();
+
+$person->add_favorite_number(7);
+$person->add_favorite_number(42);
+
+print "$_\n"
+ for $person->favorite_numbers;
+
+# 7
+# 42
+
+
+
+
Native Delegation
-
package Stack;
+
+ - Native types are ...
+
+ - Number -
add
, mul
, ...
+ - String -
append
, chop
, ...
+ - Counter -
inc
, dec
, ...
+ - Bool -
set
, toggle
, ...
+ - Hash -
get
, set
, ...
+ - Array - already saw it
+ - Code -
execute
, that's it
+
+
+
+
+
+
+
Curried Delegation
+
+
+ - A delegation with some preset arguments
+ - Works with object or Native delegation
+
+
+
+
+
Curried Delegation
+
+
package Person;
use Moose;
-has depth => (
- traits => [ 'Counter' ],
- is => 'ro',
- isa => 'Int',
- default => 0,
- init_arg => undef,
- handles =>
- { _inc_depth => 'inc',
- _dec_depth => 'dec',
- },
+has account => (
+ is => 'ro',
+ isa => 'BankAccount',
+ handles => {
+ receive_100 =>
+ [ 'deposit', 100 ]
+ give_100 =>
+ [ 'withdraw', 100 ]
+ },
);
-
Traits and Metaclasses