From: Arthur Axel 'fREW' Schmidt Date: Fri, 12 Nov 2010 01:37:50 +0000 (-0600) Subject: tests for handles X-Git-Tag: 0.009001~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f343f5cd95883376dbe6cd19a4db577bcf0fbc7;p=gitmo%2FMoo.git tests for handles --- diff --git a/t/accessor-handles.t b/t/accessor-handles.t new file mode 100644 index 0000000..aee5958 --- /dev/null +++ b/t/accessor-handles.t @@ -0,0 +1,52 @@ +use strictures 1; +use Test::More; + +{ + package Robot; + + use Moo::Role; + + requires 'smash'; + +} + +{ + package Foo; + + use Moo; + + with 'Robot'; + + sub one {1} + sub two {2} + sub smash {'smash'} + sub yum {$_[1]} +} + +{ + package Bar; + + use Moo; + + has foo => ( is => 'ro', handles => [ qw(one two) ] ); + has foo2 => ( is => 'ro', handles => { un => 'one' } ); + has foo3 => ( is => 'ro', handles => 'Robot' ); + has foo4 => ( is => 'ro', handles => { + eat_curry => [ yum => 'Curry!' ], + }); +} + +my $bar = Bar->new( + foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new +); + +is $bar->one, 1, 'handles works'; +is $bar->two, 2, 'handles works for more than one method'; + +is $bar->un, 1, 'handles works for aliasing a method'; + +is $bar->smash, 'smash', 'handles works for a role'; + +is $bar->eat_curry, 'Curry!', 'handles works for currying'; + +done_testing;