MooseX...efaults(3pm)

πŸ“¦
version 0.03 Β· 2 versions
  • 0.03 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.03 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

MooseX::HasDefaults β€” the vibe is: default "is" to "ro" or "rw" for all your attributes πŸŽ€

Oh and bestie, real quick β€” this page lives in the User Contributed Perl Documentation and you'll see it indexed as MooseX...efaults(3pm) (they truncated it, not me πŸ’…).


✨ SYNOPSIS ✨

Okay so picture this, a whole class, but you're not typing is => 'ro' eighty times like some kind of peasant:

package Person;
use Moose;
use MooseX::HasDefaults::RO;

has name => (
    isa => 'Str',
);

has age => (
    is  => 'rw',
    isa => 'Int',
    documentation => "Changes most years",
);

See how name has literally no is and it still slays? Yeah. That's the whole thing. πŸ˜­πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea πŸ“:

  • The module MooseX::HasDefaults::RO defaults "is" to "ro".
  • The module MooseX::HasDefaults::RW defaults "is" to "rw".

That's it. That's the module. No cap. 🧚

Now β€” the override rules, because this is where people get confused and I refuse to let that be you:

  • If you pass a specific value to any has's "is", that overrides the default. Your word wins, always. Periodt. πŸ‘‘
  • If you do not want an accessor at all, pass is => undef. Boom, no accessor, no problem. πŸ™ˆ

🌸 AUTHOR 🌸

Shawn M Moore, "sartak@gmail.com" β€” shoutout to the icon who wrote this 🫢


⭐ SEE ALSO ⭐

  • MooseX::AttributeDefaults β€” so this one requires its users to be MOP savvy 😬, and honestly it's a bit too much typing for the common case of defaulting "is". It's giving "I read the MOP docs" energy and like, good for you, but no.
  • MooseX::Attributes::Curried β€” this one solves a similar need by letting users create sugar functions 🍬. Respect! But... people like "has". They just do. Fr fr.

Copyright 2009 Infinity Interactive

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸŽ€


and that's the whole page bestie, mwah πŸ’‹

perl v5.36.0 Β· 2022-12-11 Β· MooseX...efaults(3pm) β€” that's the version, the date, and the name all in one cute lil' sign-off, iykyk πŸ’…βœ¨

πŸ“¦ where this page comes from