On Mon, Oct 12, 2009 at 12:09:26PM -0400, Hans Dieter Pearcey wrote:
> The fact that a hammer's no good for washing clothes doesn't mean you can't
> still bash nails with it.
>
> package HasRobot;
> use Moose::Role;
> requires @some_methods;
>
> has robot_arm => (
> is => 'ro',
> isa => 'RobotArm',
> lazy => 1,
> default => sub { RobotArm->new({ to_draw => shift }) },
> handles => { draw_with_arm => 'draw' },
> );
>
> (If you don't like hardcoding draw_with_arm, use MooseX::Role::Parameterized
> to
> refactor it.)
>
> Alternately, make a RobotArm::Drawable role that just requires @some_methods.
Alternatively again:
package RobotArmLike;
use Moose::Role;
requires 'draw_with_arm';
package RobotArm;
use Moose;
with 'RobotArmLike';
sub draw_with_arm { ... }
package Thing;
use Moose;
has robot_arm => (
is => 'ro',
does => 'RobotArmLike',
handles => 'RobotArmLike',
default => sub { RobotArm->new(to_draw => shift) },
);
since delegation can delegate to the list of methods provided by a role.
-doy