fixed the test for method modifiers
[gitmo/Moose.git] / lib / Moose / Cookbook / Recipe7.pod
CommitLineData
5de2944f 1
2=pod
3
4=head1 NAME
5
6Moose::Cookbook::Recipe7 - Making Moose fast with immutable
7
8=head1 SYNOPSIS
9
10 package Point;
11 use Moose;
12
13 has 'x' => (isa => 'Int', is => 'ro');
14 has 'y' => (isa => 'Int', is => 'rw');
15
16 __PACKAGE__->meta->make_immutable;
17
18=head1 DESCRIPTION
19
20The Moose metaclass API provides a method C<make_immutable()>. At a
21high level, this calling this method does two things to your
22class. One, it makes it faster. In particular, object construction and
23accessors are effectively "inlined" in your class, and no longer go
24through the meta-object system.
25
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 don't
28usually need to do this at runtime after first loading the class.
29
30=head2 Immutabilization and C<new()>
31
32If you override C<new()> in your class, then the immutabilization code
33will not be able to provide an optimized constructor for your
34class. Instead, consider providing a C<BUILD()> method. You can
35probably do the same thing in a C<BUILD()> method.
36
37Alternately, if you really need to provide a different C<new()>, you
38can also provide your own immutabilization method.
39
40Discussing this is beyond the scope of this recipe, however.
41
42=head1 CONCLUSION
43
44We strongly recommend you make your classes immutable. It makes your
45code much faster, basically for free. This will be especially
46noticeable when creating many objects or calling accessors frequently.
47
48=head1 AUTHOR
49
50Dave Rolsky E<lt>autarch@urth.orgE<gt>
51
52=head1 COPYRIGHT AND LICENSE
53
54Copyright 2006-2008 by Infinity Interactive, Inc.
55
56L<http://www.iinteractive.com>
57
58This library is free software; you can redistribute it and/or modify
59it under the same terms as Perl itself.
60
61=cut