Commit | Line | Data |
daa0fd7d |
1 | package Moose::Cookbook::Basics::Recipe7; |
5de2944f |
2 | |
daa0fd7d |
3 | # ABSTRACT: Making Moose fast with immutable |
4 | |
5 | __END__ |
5de2944f |
6 | |
5de2944f |
7 | |
daa0fd7d |
8 | =pod |
5de2944f |
9 | |
10 | =head1 SYNOPSIS |
11 | |
12 | package Point; |
13 | use Moose; |
14 | |
c765b254 |
15 | has 'x' => ( isa => 'Int', is => 'ro' ); |
16 | has 'y' => ( isa => 'Int', is => 'rw' ); |
5de2944f |
17 | |
18 | __PACKAGE__->meta->make_immutable; |
19 | |
20 | =head1 DESCRIPTION |
21 | |
1a5d5ecd |
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 |
6cf7fc6e |
25 | effectively "inlined" in your class, and no longer invoke the meta |
1a5d5ecd |
26 | API. |
5de2944f |
27 | |
1a5d5ecd |
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. |
5de2944f |
31 | |
32 | =head1 CONCLUSION |
33 | |
34 | We strongly recommend you make your classes immutable. It makes your |
1a5d5ecd |
35 | code much faster, with a small compile-time cost. This will be |
29d20c64 |
36 | especially noticeable when creating many objects. |
5de2944f |
37 | |
5de2944f |
38 | =cut |