Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 59613
Status: resolved
Priority: 0/
Queue: Moose

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

Bug Information
Severity: Important
Broken in: 1.08
Fixed in: 1.16



Subject: Native Types providing _default_default (ie: String ) don't work with lazy_build
Any native trait with _default_default will populate the attributes 'default' field in the absence of one. In the case of people using 'lazy_build' instead of default => , this results in a moose failure. A not very obvious to explain failure at that. ( Had to randomly comment out lines to try work out what was causing it :/ ) # died: You can not use lazy_build and default for the same attribute (myattr) at /usr/lib64/perl5/vendor_perl/5.12.1/x86_64-linux-thread-multi/Class/MOP/Method/Wrapped.pm line 48 Attached is a Test::Exception + Test::More test that should report when this feature returns to working =).
Subject: stringtrait.pl
#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; use Test::Exception; lives_ok( sub { eval <<'EOF' or die; }, 'Lazy_build + Native Traits work ' ); package Example; use Moose; has myotherattr => ( is => 'rw', isa => 'Str', ); has myattr => ( # Eval Line 10 is => 'rw', lazy_build => 1, # This isa => 'Str', traits => ['String'], # Plus This == FAIL. handles => { append_myattr => 'append' } ); sub _build_myattr { my $self = shift; return $self->myootherattr . "<< Implicit"; } 1; EOF
For anyone else experiencing this fun, a temporary and nasty workaround is as follows: use Moose::Meta::Attribute::Native::Trait::String; use Package::Stash; my $ob = Package::Stash->new('Moose::Meta::Attribute::Native::Trait::String'); $ob->remove_package_glob('_default_default');
Subject: Re: [rt.cpan.org #59613] Native Types providing _default_default (ie: String ) don't work with lazy_build
Date: Thu, 22 Jul 2010 15:20:10 -0400
To: bug-Moose [...] rt.cpan.org
From: Shawn M Moore <sartak [...] gmail.com>
(7/22/10 2:24 AM), Kent Fredric via RT wrote: Show quoted text
> Any native trait with _default_default will populate the attributes > 'default' field in the absence of one. In the case of people using > 'lazy_build' instead of default => , this results in a moose failure.
I remember campaigning that the native traits should not be setting a default for various reasons, not least of which is this kind of issue. These defaults makes it difficult to require a value provided by the end user. We should just drop these defaults altogether. I've pushed a branch, native-trait-defaults, to do exactly this. It has your test too. Shawn
On Thu Jul 22 02:24:40 2010, KENTNL wrote: Show quoted text
> Any native trait with _default_default will populate the attributes > 'default' field in the absence of one. In the case of people using > 'lazy_build' instead of default => , this results in a moose failure.
This default default and default is feature are deprecated in the latest version of Moose (1.15). They've always been fairly broken, so we really want to get rid of them. The next release will fix this bug, though.