From: Christian Walde Date: Mon, 11 Feb 2013 12:23:54 +0000 (+0100) Subject: handles => "RoleName" should try to load the module X-Git-Tag: v1.001000~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=baa7d706ec5069cd0d81920aab258504653fd093;p=gitmo%2FMoo.git handles => "RoleName" should try to load the module --- diff --git a/Changes b/Changes index c6f9fff..f0b6215 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + - handles => "RoleName" tries to load the module + 1.000008 - 2013-02-06 - Re-export on 'use Moo' after 'no Moo' - Export meta() into roles (but mark as non-method to avoid composing it) diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index c1ce749..1a13a56 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -7,6 +7,7 @@ use Sub::Quote; use B 'perlstring'; use Scalar::Util 'blessed'; use overload (); +use Module::Runtime qw(use_module); BEGIN { our $CAN_HAZ_XS = !$ENV{MOO_XS_DISABLE} @@ -145,7 +146,7 @@ sub generate_method { map [ $_ => ref($hspec->{$_}) ? @{$hspec->{$_}} : $hspec->{$_} ], keys %$hspec; } elsif (!ref($hspec)) { - map [ $_ => $_ ], Role::Tiny->methods_provided_by($hspec); + map [ $_ => $_ ], use_module('Role::Tiny')->methods_provided_by(use_module($hspec)) } else { die "You gave me a handles of ${hspec} and I have no idea why"; } diff --git a/t/accessor-handles.t b/t/accessor-handles.t index aee5958..a0df36c 100644 --- a/t/accessor-handles.t +++ b/t/accessor-handles.t @@ -1,12 +1,21 @@ use strictures 1; use Test::More; +use lib "t/lib"; + +{ + package Baz; + use Moo; + sub beep {'beep'} +} + { package Robot; use Moo::Role; requires 'smash'; + $INC{"Robot.pm"} = 1; } @@ -34,10 +43,12 @@ use Test::More; has foo4 => ( is => 'ro', handles => { eat_curry => [ yum => 'Curry!' ], }); + has foo5 => ( is => 'ro', handles => 'ExtRobot' ); } my $bar = Bar->new( - foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new + foo => Foo->new, foo2 => Foo->new, foo3 => Foo->new, foo4 => Foo->new, + foo5 => Baz->new ); is $bar->one, 1, 'handles works'; @@ -47,6 +58,8 @@ is $bar->un, 1, 'handles works for aliasing a method'; is $bar->smash, 'smash', 'handles works for a role'; +is $bar->beep, 'beep', 'handles loads roles'; + is $bar->eat_curry, 'Curry!', 'handles works for currying'; done_testing; diff --git a/t/lib/ExtRobot.pm b/t/lib/ExtRobot.pm new file mode 100644 index 0000000..95d73a6 --- /dev/null +++ b/t/lib/ExtRobot.pm @@ -0,0 +1,7 @@ +package ExtRobot; + +use Moo::Role; + +requires 'beep'; + +1;