Subject: | Basic role implementation failing - <Role> requires the method '<method_name> to be implemented by '<class>' |
Date: | Wed, 26 Oct 2011 14:22:25 +0100 |
To: | bug-MooseX-Declare [...] rt.cpan.org |
From: | NOEL DOLAN <noelt.dolan [...] virgin.net> |
Hi,
I'm getting an error when trying to implement a role against a class (as
detailed below). The error goes away if I uncomment the 'dummy' method in
the CPersonMD class - however, this only works if the dummy method is
declared AFTER the 'name' method, not before it.
-- Environment
System : FreeBSD 8.2
Perl : 5.12.4
Moose : 2.0205
MooseX::Declare : 0.35
--
-- start - role : RPersonMD.pm
--
use MooseX::Declare;
role RPersonMD
{
requires qw( name );
}
-- end -
--
-- start - class : CPersonMD.pm
--
use MooseX::Declare;
class CPersonMD with RPersonMD
{
method name()
{
print "my name is mud!\n";
}
#method dummy(){}
}
-- end -
--
-- start - script : test_md.pl
--
#!/usr/bin/perl
use strict;
use warnings;
use CPersonMD;
my $person = CPersonMD->new();
$person->name();
exit(1);
-- end -
--
-- Start - Error Message
--
'RPersonMD' requires the method 'name' to be implemented by 'CPersonMD' at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Meta/Role/Application/ToClass.pm
line 127
Moose::Meta::Role::Application::ToClass::check_required_methods('Moose::Meta::Role::Application::ToClass=HASH(0x29598500)',
'Moose::Meta::Role=HASH(0x2965f320)', 'Moose::Meta::Class=HASH(0x29587de8)')
called at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Meta/Role/Application.pm
line 55
Moose::Meta::Role::Application::apply('Moose::Meta::Role::Application::ToClass=HASH(0x29598500)',
'Moose::Meta::Role=HASH(0x2965f320)', 'Moose::Meta::Class=HASH(0x29587de8)')
called at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Meta/Role/Application/ToClass.pm
line 35
Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role::Application::ToClass=HASH(0x29598500)',
'Moose::Meta::Role=HASH(0x2965f320)', 'Moose::Meta::Class=HASH(0x29587de8)',
'HASH(0x295f2848)') called at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Meta/Role.pm line 470
Moose::Meta::Role::apply('Moose::Meta::Role=HASH(0x2965f320)',
'Moose::Meta::Class=HASH(0x29587de8)') called at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Util.pm line 159
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x29587de8)',
undef, 'RPersonMD') called at
/usr/local/lib/perl5/site_perl/5.12.4/mach/Moose/Util.pm line 98
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x29587de8)',
'RPersonMD') called at CPersonMD.pm line 8
require CPersonMD.pm called at ./test_md.pl line 5
main::BEGIN() called at CPersonMD.pm line 0
eval {...} called at CPersonMD.pm line 0
Compilation failed in require at ./test_md.pl line 5.
BEGIN failed--compilation aborted at ./test_md.pl line 5.
-- end -
For comparison, the above works as expected in the following environment.
-- Environment
System : Ubuntu 8.04
Perl : 5.10.1
Moose : 2.0007
MooseX::Declare : 0.34
Regards,
Noel