Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

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

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

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



Subject: In a subclass which overrides an attribute and its builder, the overridden builder is ignored
Moo 2.003 If an attribute is overridden in a subclass, an overridden builder is ignored. Here's example code. * Foo is the base class with an attribute with a builder. * Bar extends Foo, overriding both the attribute and its builder * Blg extends Foo, overriding only the builder. { package Foo; use Moo; has 'attr' => ( is => 'ro', builder => sub { print __PACKAGE__, "\n" } ); } { package Bar; use Moo; extends 'Foo'; has '+attr' => ( init_arg => undef ); sub _build_attr { print __PACKAGE__, "\n" } } { package Blg; use Moo; extends 'Foo'; sub _build_attr { print __PACKAGE__, "\n" } } Foo->new->attr; Bar->new->attr; Blg->new->attr; I expect the output to be Foo Bar Blg however, it's Foo Foo Blg Thanks, Diab
On Fri Mar 03 10:59:20 2017, DJERIUS wrote: Show quoted text
> Moo 2.003 > > If an attribute is overridden in a subclass, an overridden builder is > ignored. > > Here's example code. > > * Foo is the base class with an attribute with a builder. > * Bar extends Foo, overriding both the attribute and its builder > * Blg extends Foo, overriding only the builder. > > { > package Foo; > use Moo; > has 'attr' => ( > is => 'ro', > builder => sub { print __PACKAGE__, "\n" } > ); > } > > { > package Bar; > use Moo; > extends 'Foo'; > has '+attr' => ( init_arg => undef );
Explicitly setting builder to a coderef provides a workaround: has '+attr' => ( init_arg => undef, builder => \&_build_attr ); This doesn't help: has '+attr' => ( init_arg => undef, builder => 1 );
Fixed in v2.003001
Subject: Re: [rt.cpan.org #120489] In a subclass which overrides an attribute and its builder, the overridden builder is ignored
Date: Mon, 6 Mar 2017 13:38:20 -0500
To: bug-Moo [...] rt.cpan.org
From: Diab Jerius <djerius [...] cpan.org>
Thanks! On Mon, Mar 6, 2017 at 12:06 PM, Graham Knop via RT <bug-Moo@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=120489 > > > Fixed in v2.003001