Commit | Line | Data |
5de2944f |
1 | |
2 | =pod |
3 | |
4 | =head1 NAME |
5 | |
021b8139 |
6 | Moose::Cookbook::Basics::Recipe7 - Making Moose fast with immutable |
5de2944f |
7 | |
8 | =head1 SYNOPSIS |
9 | |
10 | package Point; |
11 | use Moose; |
12 | |
c765b254 |
13 | has 'x' => ( isa => 'Int', is => 'ro' ); |
14 | has 'y' => ( isa => 'Int', is => 'rw' ); |
5de2944f |
15 | |
16 | __PACKAGE__->meta->make_immutable; |
17 | |
18 | =head1 DESCRIPTION |
19 | |
1a5d5ecd |
20 | The Moose metaclass API provides a C<make_immutable()> method. Calling |
21 | this method does two things to your class. First, it makes it |
22 | faster. In particular, object construction and destruction are |
23 | effectively "inlined" in your class, and no longer invokes the meta |
24 | API. |
5de2944f |
25 | |
1a5d5ecd |
26 | Second, you can no longer make changes via the metaclass API, such as |
27 | adding attributes. In practice, this won't be a problem, as you rarely |
28 | need to do this after first loading the class. |
5de2944f |
29 | |
30 | =head1 CONCLUSION |
31 | |
32 | We strongly recommend you make your classes immutable. It makes your |
1a5d5ecd |
33 | code much faster, with a small compile-time cost. This will be |
34 | especially noticeable when creating many object. |
5de2944f |
35 | |
36 | =head1 AUTHOR |
37 | |
38 | Dave Rolsky E<lt>autarch@urth.orgE<gt> |
39 | |
40 | =head1 COPYRIGHT AND LICENSE |
41 | |
2840a3b2 |
42 | Copyright 2006-2009 by Infinity Interactive, Inc. |
5de2944f |
43 | |
44 | L<http://www.iinteractive.com> |
45 | |
46 | This library is free software; you can redistribute it and/or modify |
47 | it under the same terms as Perl itself. |
48 | |
49 | =cut |