I've finally buckled to peer pressure and adopted Moose. So far I /
really/ like it. Thanks.
I'm having a problem that may well just be me doing something silly.
Given the following:
$ cat Configurable.pm
package Configurable;
use Moose::Role;
use Configuration;
has 'config' => (
handles => ['option'],
default => sub { Configuration->new },
);
#sub option { 'fake' }
1;
$ cat Configuration.pm
package Configuration;
use Moose;
sub option { 'option value' }
1;
$ cat Loggable.pm
package Loggable;
use Moose::Role;
requires 'option';
sub log { print 'Option is ', shift->option, "\n" }
1;
$ cat Thing.pm
package Thing;
use Moose;
with 'Configurable', 'Loggable';
sub run { shift->log }
1;
I get this:
$ perl -MThing -e 'Thing->new->run'
'Configurable|Loggable' requires the method 'option' to be
implemented by 'Thing' at /alt/local/lib/perl5/site_perl/5.10.0/Moose/
Meta/Role/Application.pm line 59
Moose
::Meta
::Role
::Application
::apply('Moose::Meta::Role::Application::ToClass=HASH(0x854b5f8)',
'Moose::Meta::Role::Composite=HASH(0x84be570)',
'Moose::Meta::Class=HASH(0x84b8dc0)') called at /alt/local/lib/perl5/
site_perl/5.10.0/Moose/Meta/Role/Application/ToClass.pm line 17
Moose
::Meta
::Role
::Application
::ToClass
::apply('Moose::Meta::Role::Application::ToClass=HASH(0x854b5f8)',
'Moose::Meta::Role::Composite=HASH(0x84be570)',
'Moose::Meta::Class=HASH(0x84b8dc0)') called at /alt/local/lib/perl5/
site_perl/5.10.0/Moose/Meta/Role.pm line 447
Moose
::Meta::Role::apply('Moose::Meta::Role::Composite=HASH(0x84be570)',
'Moose::Meta::Class=HASH(0x84b8dc0)') called at /alt/local/lib/perl5/
site_perl/5.10.0/Moose/Util.pm line 96
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x84b8dc0)',
'Configurable', 'Loggable') called at /alt/local/lib/perl5/site_perl/
5.10.0/Moose.pm line 70
Moose::with('Thing', 'Configurable', 'Loggable') called at /alt/
local/lib/perl5/site_perl/5.10.0/Moose/Exporter.pm line 192
Moose::with('Configurable', 'Loggable') called at Thing.pm line 5
require Thing.pm called at -e line 0
main::BEGIN() called at Thing.pm line 0
eval {...} called at Thing.pm line 0
Compilation failed in require.
BEGIN failed--compilation aborted.
If I uncomment the implementation of C<option> in Configurable.pm it
works
just fine - and delegates correctly to the C<option> in
Configuration.pm.
If I comment out the 'requires' in Loggable it also works fine.
So I guess the combination of delegation and role composition puts the
implementation of C<option> out of reach to requires?
Am I doing something silly?
--
Andy Armstrong, Hexten