Skip Menu |

This queue is for tickets about the MooseX-Declare CPAN distribution.

Report information
The Basics
Id: 48583
Status: resolved
Priority: 0/
Queue: MooseX-Declare

People
Owner: Nobody in particular
Requestors: maik.hentsche [...] amd.com
Cc:
AdminCc:

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



Subject: Can't inherit start() from role MooseX::Daemonize
This code: use MooseX::Declare; class Foo with MooseX::Daemonize { after start { $self->printout();} method printout(){ print "test\n"; die "Autsch"; } } fails with The method 'start' was not found in the inheritance hierarchy for Foo at /home/mhentsc3/perl510/lib/site_perl/5.10.0/x86_64- linux/Class/MOP/Class.pm line 660 This code should behave similar to the following code: package Foo; use Moose; with 'MooseX::Daemonize'; after 'start' => sub { my $self = shift @_; $self->printout();}; sub printout { my $self = shift @_; print "hello\n"; die "autsch";} 1; package main; my $x = Foo->new(pidfile => '/tmp/foo.pid'); $x->start(); The second code snippet works.
From: maik.hentsche [...] amd.com
Further investigation suggests roles don't work at all: use MooseX::Declare; use 5.010; role FooRole { method start { say "Inside FooRole->start";}} class Foo with FooRole { after start { say "Inside Foo->after_start";} } This gives the same error message: The method 'start' was not found in the inheritance hierarchy for Foo [..]
Subject: Re: [rt.cpan.org #48583] Can't inherit start() from role MooseX::Daemonize
Date: Mon, 10 Aug 2009 09:27:27 -0400
To: bug-MooseX-Declare [...] rt.cpan.org
From: Chris Prather <perigrin [...] gmail.com>
On Mon, Aug 10, 2009 at 8:03 AM, Maik Hentsche via RT<bug-MooseX-Declare@rt.cpan.org> wrote: Show quoted text
>       Queue: MooseX-Declare >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=48583 > > > Further investigation suggests roles don't work at all: > > > use MooseX::Declare; > > use 5.010; > > role FooRole { method start { say "Inside FooRole->start";}} > > class Foo with FooRole { >        after start { say "Inside Foo->after_start";} > } > > This gives the same error message: > The method 'start' was not found in the inheritance hierarchy for Foo > [..] >
You've discovered a conflict with the way MooseX::Declare handles Roles. This is a known issue where MooseX::Declare will defer Role composition until the end of scope which solves *some* issues with Roles but causes others like you're seeing here. Try the following and see if it "fixes" the problem: use MooseX::Declare use 5.10.0; role FooRole { method start { say "Start" } } class Foo { Moose::with('FooRole'); after start { say "After" } } -Chris
On Mon Aug 10 09:27:49 2009, chris@prather.org wrote: Show quoted text
> Moose::with('FooRole');
Actually, Moose::with( __PACKAGE__, 'FooRole' ); -- Jonathan Rockway <jrockway@cpan.org>
Initially, application from roles has been defered until the end of the class definition, so that methods inside a class (or role) can satisfy method requirements from applied roles. Unfortunately that made applying method modifiers to methods composed from roles impossible. This is now fixed by not defering the role application for the 'with' statement within a class block (as opposed to the with option in the class- and role-declarators). That way you can either get the simple behaviour that works in most cases or the with keyword, which allows you to apply your roles at any point you want.