1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
use 5.008;
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{ package Local::Dummy1; use Test::Requires 'Class::Tiny' };
note 'Local::Bleh';
{
package Local::Bleh;
use Sub::HandlesVia qw( delegations );
use Class::Tiny {
nums => sub { [1..2] }, # lazy builder
};
delegations(
attribute => 'nums',
handles_via => 'Array',
handles => {
splice_nums => 'splice',
splice_nums_tap => 'splice...',
first_num => [ 'get', 0 ],
},
);
}
my $bleh = Local::Bleh->new;
my @r = $bleh->splice_nums(0, 2, 3..5);
is_deeply($bleh->nums, [3..5], 'delegated method worked');
is_deeply(\@r, [1..2], '... and returned correct value');
is($bleh->first_num, 3, 'curried delegated method worked');
$bleh = Local::Bleh->new;
@r = $bleh->splice_nums_tap(0, 2, 3..5);
is_deeply($bleh->nums, [3..5], 'delegated method with chaining worked');
is_deeply(\@r, [$bleh], '... and returned correct value');
done_testing;
|