Moose::...mutable(3)

πŸ’– NAME πŸ’–

Moose::Cookbook::Basics::Immutable β€” making Moose go zoom by making your class immutable, bestie ✨


🌸 VERSION 🌸

version 2.4000


πŸŽ€ SYNOPSIS πŸŽ€

package Point;
use Moose;

has 'x' => ( isa => 'Int', is => 'ro' );
has 'y' => ( isa => 'Int', is => 'rw' );

__PACKAGE__->meta->make_immutable;

okay so literally that's it, that last line is the whole plot twist πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So the Moose metaclass API hands you a make_immutable() method, and calling it does two things to your class. Two. Count them.

One: it makes your class faster. Like, noticeably faster. Object construction and destruction get effectively "inlined" right into your class, so they don't go bother the meta API anymore. No cap, that's a real speedup πŸ”₯

Two: after this, you can no longer make changes through the metaclass API β€” things like adding attributes? Nope, doors closed, not happening, sorry babe πŸ™ˆ

And honestly? In practice this is not a problem at all. You rarely need to do that kind of thing after the class has been loaded the first time. It's giving "no notes", fr fr.


πŸ‘‘ CONCLUSION πŸ‘‘

We strongly recommend you make your classes immutable. It makes your code much faster, and the only cost is a small one at compile time. And the way that this hits different when you're creating a whole bunch of objects? iconic. Slay. Periodt. πŸ’…βœ¨


🌈 AUTHORS 🌈

The absolute legends who made this happen, no big deal, just the main characters πŸ‘‘

  • Stevan Little <stevan@cpan.org>
  • Dave Rolsky <autarch@urth.org>
  • Jesse Luehrs <doy@cpan.org>
  • Shawn M Moore <sartak@cpan.org>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>
  • Karen Etheridge <ether@cpan.org>
  • Florian Ragwitz <rafl@debian.org>
  • Hans Dieter Pearcey <hdp@cpan.org>
  • Chris Prather <chris@prather.org>
  • Matt S Trout <mstrout@cpan.org>

This software is copyright (c) 2006 by Infinity Interactive, Inc. πŸ’œ

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole vibe check, bestie 🧚 this was Moose::...mutable(3) from the User Contributed Perl Documentation, running on perl v5.42.0, dated 2025-07-25 β€” tysm for reading, go make your classes immutable, ily πŸ’–

πŸ“¦ where this page comes from