1Moose::Cookbook::BasicsU:s:eIrmmCuotnatbrlieb(u3t)ed PerMlooDsoec:u:mCeonotkabtoiookn::Basics::Immutable(3)
2
3
4
6 Moose::Cookbook::Basics::Immutable - Making Moose fast by making your
7 class immutable
8
10 version 2.2014
11
13 package Point;
14 use Moose;
15
16 has 'x' => ( isa => 'Int', is => 'ro' );
17 has 'y' => ( isa => 'Int', is => 'rw' );
18
19 __PACKAGE__->meta->make_immutable;
20
22 The Moose metaclass API provides a "make_immutable()" method. Calling
23 this method does two things to your class. First, it makes it faster.
24 In particular, object construction and destruction are effectively
25 "inlined" in your class, and no longer invoke the meta API.
26
27 Second, you can no longer make changes via the metaclass API, such as
28 adding attributes. In practice, this won't be a problem, as you rarely
29 need to do this after first loading the class.
30
32 We strongly recommend you make your classes immutable. It makes your
33 code much faster, with a small compile-time cost. This will be
34 especially noticeable when creating many objects.
35
37 • Stevan Little <stevan@cpan.org>
38
39 • Dave Rolsky <autarch@urth.org>
40
41 • Jesse Luehrs <doy@cpan.org>
42
43 • Shawn M Moore <sartak@cpan.org>
44
45 • יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
46
47 • Karen Etheridge <ether@cpan.org>
48
49 • Florian Ragwitz <rafl@debian.org>
50
51 • Hans Dieter Pearcey <hdp@cpan.org>
52
53 • Chris Prather <chris@prather.org>
54
55 • Matt S Trout <mstrout@cpan.org>
56
58 This software is copyright (c) 2006 by Infinity Interactive, Inc.
59
60 This is free software; you can redistribute it and/or modify it under
61 the same terms as the Perl 5 programming language system itself.
62
63
64
65perl v5.32.1 2021-01-M2o7ose::Cookbook::Basics::Immutable(3)