X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-handles.t;h=2125784420425d2b0636ec47cad7a3d4df224a66;hb=e18659958c8a6bf3fc60b9531e40acbea275076f;hp=a0df36cc0cc1b8e1ea2bd6386933e591e9782e51;hpb=baa7d706ec5069cd0d81920aab258504653fd093;p=gitmo%2FMoo.git diff --git a/t/accessor-handles.t b/t/accessor-handles.t index a0df36c..2125784 100644 --- a/t/accessor-handles.t +++ b/t/accessor-handles.t @@ -1,5 +1,6 @@ use strictures 1; use Test::More; +use Test::Fatal; use lib "t/lib"; @@ -7,6 +8,8 @@ use lib "t/lib"; package Baz; use Moo; sub beep {'beep'} + + sub is_passed_undefined { !defined($_[0]) ? 'bar' : 'fail' } } { @@ -44,6 +47,13 @@ use lib "t/lib"; eat_curry => [ yum => 'Curry!' ], }); has foo5 => ( is => 'ro', handles => 'ExtRobot' ); + has foo6 => ( is => 'rw', + handles => { foobot => '${\\Baz->can("beep")}'}, + default => sub { 0 } ); + has foo7 => ( is => 'rw', + handles => { foobar => '${\\Baz->can("is_passed_undefined")}'}, + default => sub { undef } ); + } my $bar = Bar->new( @@ -62,4 +72,23 @@ is $bar->beep, 'beep', 'handles loads roles'; is $bar->eat_curry, 'Curry!', 'handles works for currying'; +is $bar->foobot, 'beep', 'asserter checks for existence not truth, on false value'; + +is $bar->foobar, 'bar', 'asserter checks for existence not truth, on undef '; + +ok(my $e = exception { + package Baz; + use Moo; + has foo => ( is => 'ro', handles => 'Robot' ); + sub smash { 1 }; +}, 'handles will not overwrite locally defined method'); +like $e, qr{You cannot overwrite a locally defined method \(smash\) with a delegation}, + '... and has correct error message'; + +ok(exception { + package Fuzz; + use Moo; + has foo => ( is => 'ro', handles => $bar ); +}, 'invalid handles throws exception'); + done_testing;