Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 81816
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: RSAVAGE [...] cpan.org
Cc:
AdminCc:

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



Subject: Default not set, and dies in BUILD(), when used with Moo::Role
See attached. Unpack and run: perl -Ilib scripts/test.pl Output (3 lines): ron@zigzag:~/perl.modules/Local-MooDemo1$ perl -Ilib scripts/test.pl Use of uninitialized value in say at lib/Local/MooDemo1.pm line 24. Initial value of config: ron@zigzag:~/perl.modules/Local-MooDemo1$ Comment out line 7: use Moo::Role; and the scripts runs ok.
Subject: Local-MooDemo1-1.00.tar.gz
Download Local-MooDemo1-1.00.tar.gz
application/x-gzip 5.2k

Message body not shown because it is not plain text.

I'm not especially surprised this doesn't work. Moo and Moo::Role aren't really intended to be imported into the same package. Of course raising a compile-time error would be nice.
Here's a smaller test case... use strict; use warnings; use Test::More tests => 1; { package Local::Test; use Moo; use Moo::Role; has attr => ( is => 'ro', default => sub { 1 }, required=>0, ); sub BUILD { my $self = shift; $self->attr + 1; } } new_ok 'Local::Test';
Subject: Re: [rt.cpan.org #81816] Default not set, and dies in BUILD(), when used with Moo::Role
Date: Sun, 09 Dec 2012 12:08:18 +1100
To: bug-Moo [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Toby On 09/12/12 11:29, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=81816> > > I'm not especially surprised this doesn't work. Moo and Moo::Role aren't > really intended to be imported into the same package.
What then is the solution/alternative to wanting to use Moo/Other to create the class and Moo::Role/Other to make it a role? Show quoted text
> Of course raising a compile-time error would be nice.
Documenting the problem would be nice too..... -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Show quoted text
> What then is the solution/alternative to wanting to use Moo/Other to > create the class and Moo::Role/Other to make it a role?
Ultimately it's the same solution as when you want to create a combination paring knife and childs' toy. Stop wanting that. That said, there is a hack to make it work. Define your package (let's assume it's called "Foo") as a Moo::Role, then at the *end* of the package add: our @ISA = do { package Foo::_; use Moo; with 'Foo'; __PACKAGE__ }; I'll leave figuring out why that works as an exercise for the reader. :-)
Subject: Re: [rt.cpan.org #81816] Default not set, and dies in BUILD(), when used with Moo::Role
Date: Sun, 09 Dec 2012 13:21:23 +1100
To: bug-Moo [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Toby On 09/12/12 12:31, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=81816> >
>> What then is the solution/alternative to wanting to use Moo/Other to >> create the class and Moo::Role/Other to make it a role?
> > Ultimately it's the same solution as when you want to create a > combination paring knife and childs' toy. Stop wanting that.
He, he, he. Show quoted text
> That said, there is a hack to make it work. Define your package (let's > assume it's called "Foo") as a Moo::Role, then at the *end* of the > package add: > > our @ISA = do { package Foo::_; use Moo; with 'Foo'; __PACKAGE__ }; > > I'll leave figuring out why that works as an exercise for the reader. :-)
Reversal of roles? My hack will be to drop Moo::Role, and use 'extends'. Thanx. I'd better start re-writing my article. Mega-pain. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
This branch on git provides an exception when somebody tries to create a package that is both a Moo class and a Moo role: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/ Moo.git;a=shortlog;h=refs/heads/moo-chimera-warning-rt81727
Subject: Re: [rt.cpan.org #81816] Default not set, and dies in BUILD(), when used with Moo::Role
Date: Mon, 10 Dec 2012 11:12:36 +1100
To: bug-Moo [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Toby On 09/12/12 23:42, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=81816> > > This branch on git provides an exception when somebody tries to create a > package that is both a Moo class and a Moo role: > > http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/ > Moo.git;a=shortlog;h=refs/heads/moo-chimera-warning-rt81727
Great idea. $many x $thanx; -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
On Sun Dec 09 19:18:12 2012, ron@savage.net.au wrote: Show quoted text
> Hi Toby > > > On 09/12/12 23:42, Toby Inkster via RT wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=81816> > > > > This branch on git provides an exception when somebody tries to create a > > package that is both a Moo class and a Moo role: > > > > http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/ > > Moo.git;a=shortlog;h=refs/heads/moo-chimera-warning-rt81727
> > Great idea. $many x $thanx;
Released in 1.0.7 Cheers gentlemen.