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 3223962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:10:04+00:00 2026-05-17T16:10:04+00:00

In Moose you can declare a group of attributes at once, assuming the initialization

  • 0

In Moose you can declare a group of attributes at once, assuming the initialization parameters are the same:

has [qw( foo bar baz )] => (
    is => 'ro',
    isa => 'Str',
    required => 1,
);

This is a lovely feature that saves a ton of typing. However, I find myself puzzled about how define a predicate, clearer or even a builder method using this syntax.

has 'foo' => (
    is        => 'ro',
    isa       => 'Str',
    required  => 1,
    clearer   => 'clear_foo',
    predicate => 'has_foo',
);

Is there a parameter I can use that will build standard ‘has_X, 'clear_X and _build_X methods for all the attributes in my list?

  • 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-17T16:10:05+00:00Added an answer on May 17, 2026 at 4:10 pm
    has $_ => (
        is => 'ro',
        isa => 'Str',
        required => 1,
        clearer => '_clear_' . $_,
        # etc...
    ) for (qw(foo bar baz);
    

    Note that lazy_build => 1 will automatically generate clearers, and
    predicates, but they will always be public, which is starting to be frowned
    upon in the Moose community. (I don’t think anyone’s blogged about this yet,
    but it’s been a topic of conversation on IRC #moose of late.)

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

Sidebar

Related Questions

How can I declare a class variable as floating point in Moose? My (fictional)
Moose::Manual::Attributes states: As an alternative to using a subroutine reference [for default], you can
Consider this simple class: package Foo; use Moose; has foo => ( is =>
How can I get ctags to generate tags for MooseX::Declare methods, classes, attributes and
I'm trying to get a moose object, which has moose objects to be referenced
Here's something weird that I can't figure out. I have a Moose class that
I'm still new to moose, but it has me drooling! Below is a simplified
I'd like to create a structured type in Moose that can be used as
I'm learning Modern perl - Moose, Plack etc. In much advices you can read
Consider the following code: package Test1; use Moose; has 'something' => ( is =>

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.