Skip Menu |

This queue is for tickets about the Moops CPAN distribution.

Report information
The Basics
Id: 92757
Status: resolved
Priority: 0/
Queue: Moops

People
Owner: Nobody in particular
Requestors: sven.schober [...] uni-ulm.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: method definition not satisfying role requirement
Date: Wed, 05 Feb 2014 17:19:27 +0100
To: bug-Moops [...] rt.cpan.org
From: Sven Schober <sven.schober [...] uni-ulm.de>
I'm using Moops 0.030 and Perl 5.18.2 on a 64bit Archlinux. The following code snippet yields an unsatisfied role requirement: use Modern::Perl; use Moops; role r1 { requires 'm1'; } class c1 with r1 { method m1 { } } c1->new(); Whereas, when I replace `method` by `sub` it works.
Download smime.p7s
application/pkcs7-signature 4.4k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #92757] AutoReply: method definition not satisfying role requirement
Date: Wed, 05 Feb 2014 17:22:12 +0100
To: bug-Moops [...] rt.cpan.org
From: Sven Schober <sven.schober [...] uni-ulm.de>
Moving the role inclusion below the method definition like so: class c1 { method m1 { } with 'r1'; } works, but seems unsatisfying.
Download smime.p7s
application/pkcs7-signature 4.4k

Message body not shown because it is not plain text.

This is basically the same issue as RT#91557. I'm not quite sure what the best route to take is, but I will do something about it soon.
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. :-(
Marking as stalled until better ideas are had.
Subject: Re: [rt.cpan.org #92757] method definition not satisfying role requirement
Date: Wed, 20 Aug 2014 12:32:06 +0200
To: bug-Moops [...] rt.cpan.org
From: Sven Schober <sven.schober [...] uni-ulm.de>
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
Download smime.p7s
application/pkcs7-signature 4.6k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #92757] method definition not satisfying role requirement
Date: Wed, 20 Aug 2014 12:32:06 +0200
To: bug-Moops [...] rt.cpan.org
From: Sven Schober <sven.schober [...] uni-ulm.de>
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
Download smime.p7s
application/pkcs7-signature 4.6k

Message body not shown because it is not plain text.

If you've got the latest Moops, and the latest Kavorka, the following should Just Work: use Moops; role r1 { after BUILD { print "r1.BUILD()\n"; }; } class Base { method BUILD { print "Base.BUILD()\n" } } class Sub extends Base with r1 { method BUILD { print "Sub.BUILD()\n"} } Sub->new();
To clarify, this is because as of Moops 0.032, role composition is delayed to the end of the class declaration. So this: class Foo extends Bar with Baz { ...; } is roughly equivalent to: package Foo { use Moo; extends "Bar"; ...; with "Baz"; } Which means that if the "..." part declared any methods, role application will happen after that. This will nearly always be what you want. And for those cases where it's not what you want, it is still possible to manually put "extends" and "with" statements inside the declaration, like this... class Foo { ...; extends "Bar"; ...; with "Baz"; ...; } ... and thus have finer grained control as to when inheritance and role composition get applied to your class.