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