1 package Moose::Cookbook::Basics::Recipe7;
3 # ABSTRACT: Making Moose fast with immutable
15 has 'x' => ( isa => 'Int', is => 'ro' );
16 has 'y' => ( isa => 'Int', is => 'rw' );
18 __PACKAGE__->meta->make_immutable;
22 The Moose metaclass API provides a C<make_immutable()> method. Calling
23 this method does two things to your class. First, it makes it
24 faster. In particular, object construction and destruction are
25 effectively "inlined" in your class, and no longer invoke the meta
28 Second, you can no longer make changes via the metaclass API, such as
29 adding attributes. In practice, this won't be a problem, as you rarely
30 need to do this after first loading the class.
34 We strongly recommend you make your classes immutable. It makes your
35 code much faster, with a small compile-time cost. This will be
36 especially noticeable when creating many objects.