The error handling is slightly misleading, currently. Consider this
short example:
use Modern::Perl '2014';
use Moops;
role r1 {
after BUILD { print "r1.BUILD()\n"; };
}
class Base {
#method BUILD { print "Base.BUILD()\n" }
}
class Sub
with r1
extends Base {
method BUILD
# but begin
{ print "Sub.BUILD()\n"}
}
package main;
Sub->new();
Excuting this gives me:
The method 'BUILD' is not found in the inheritance hierarchy for class
Sub ...
Nice, I can understand that readily.
But, when I "comment in" the BUILD()-Method in Base, I get the following:
Subroutine Sub::BUILD redefined at
/opt/perl5/perls/perl-5.21.0-shared-threaded/lib/site_perl/5.21.0/Kavorka/Sub.pm
line 79.
BEGIN failed--compilation aborted at build-redefinied.pl line 18.
Which, for me, is entirely misleading, as I redefining BUILD() in Sub
normally (without the role-inclusion) works.
I've been bitten by this now the second time and it took me a while
realizing that commenting in the "but begin" in Sub solves the problem.
I figure, you only need "but begin" in the class which does the
role-inclusion?
On 02/26/2014 02:25 PM, Toby Inkster via RT wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=92757 >
>
> If you have a recent version of Kavorka, the following should work:
>
> use Moops;
>
> role r1 {
> requires 'm1';
> }
>
> class c1 with r1 {
> method m1 but begin {
> }
> }
>
> c1->new();
>
> The "begin" trait makes the sub get installed at compile-time instead of run-time. It's not a great solution. The order in which things need to happen can be surprisingly delicate. :-(
>
--
Dipl.-Inf. Sven Schober
Universität Ulm
kiz - Abteilung Infrastruktur
89069 Ulm
Tel.: +49 731 50 22484