Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:17:33+00:00 2026-05-31T13:17:33+00:00

My Moo based class has both lazy & non-lazy attributes which have both default

  • 0

My Moo based class has both lazy & non-lazy attributes which have both default and coerce subs. If I don’t initialize the attributes I’m finding that both default and coerce subs are called for the normal attribute, but only default is called for the lazy attribute. That seems inconsistent. Here’s sample code:

package Foo;
use Moo;

has nrml => ( is => 'ro',
              default => sub { print "nrml default\n" },
              coerce  => sub { print "nrml coerce\n" } 
            );

has lazy => ( is => 'ro',
              lazy => 1,
              default => sub { print "lazy default\n" },
              coerce  => sub { print "lazy coerce\n" }
            );



my $q = Foo->new( );

$q->lazy;

The output is:

nrml default
nrml coerce
lazy default

I only expect coerce to run if I provide a value in the constructor. More importantly I expect the same sequence of execution (either default or default and coerce) from both lazy and normal attributes.

So, are my expectations off, is this a bug, or what? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:17:34+00:00Added an answer on May 31, 2026 at 1:17 pm

    Current status: fix shipped in 009014

    One of those two is a bug.

    In fact, thinking about it, one could argue either way about whether coercions -should- be fired on defaults but since Moose does do so, and since coercions are structural (unlike type checks, which are often used for assertion-like things and should always pass except in the presence of a bug), I think it falls that way.

    … in fact, the problem is that Method::Generate::Accessor when it fires _use_default always wraps it in _generate_simple_set, when it’s _generate_set that provides the isa+coerce+trigger wrapping – and I’m fairly sure that Moose fires all three when it’s applying a default, so we need to too.

    It’s not an entirely trivial fix to make though, because I didn’t parameterise _generate_set to take a value indicating how to generate the value to set. I’ll try and sort it out tomorrow since I’m planning to cut a release then.

    If you want support for Moo from the developers, please contact bugs-Moo@rt.cpan.org or join #web-simple on irc.perl.org – it’s sheer luck that somebody on the IRC channel saw this question and asked about it 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an abstract base class Animal which has public virtual abstract method
Suppose I have an interface: IFoo<T1,T2> and a class Moo<T1> : IFoo<List<T1>, Stack<T1>> .
Let's say we have this class: public class Moo { string _value; public Moo(string
I have a lot of links with the class .moo , I need jquery
So i have made my own dict-based named-tuple class: class t(dict): def __getattr__(self, v):
So I have this regex: (^(\s+)?(?P<NAME>(\w)(\d{7}))((01f\.foo)|(\.bar|\.goo\.moo\.roo))$|(^(\s+)?(?P<NAME2>R1_\d{6}_\d{6}_)((01f\.foo)|(\.bar|\.goo\.moo\.roo))$)) Now if I try and do a match
Goal: To develop a web based NMS interface which displays a network topology (e.g.,
On my page http://all-fours.pl/ I'm using moo.fx for.. something, I don't really know what.
I'm just about done Koenig & Moo's Accelerated C++ and in Chapters 13 &
My hosting sent me email saying I have set the session.save_path = /home/users/web/b1475/moo.youraccount/cgi-bin/tmp for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.