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>
π«Ά COPYRIGHT AND LICENSE π«Ά
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
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms