Class::MOP::Class::Immutable - An immutable version of Class::MOP::Class
package Point; use metaclass; __PACKAGE__->meta->add_attribute('x' => (accessor => 'x', default => 10)); __PACKAGE__->meta->add_attribute('y' => (accessor => 'y')); sub new { my $class = shift; $class->meta->new_object(@_); } sub clear { my $self = shift; $self->x(0); $self->y(0); } __PACKAGE__->meta->make_immutable(); # close the class
Class::MOP offers many benefits to object oriented development but it comes at a cost. Pure Class::MOP classes can be quite a bit slower than the typical hand coded Perl classes. This is because just about everything is recalculated on the fly, and nothing is cached. The reason this is so, is because Perl itself allows you to modify virtually everything at runtime. Class::MOP::Class::Immutable offers an alternative to this.
By making your class immutable, you are promising that you will not modify your inheritence tree or the attributes of any classes in that tree. Since runtime modifications like this are fairly atypical (and usually recomended against), this is not usally a very hard promise to make. For making this promise you are given a wide range of optimization options which bring speed close to (and sometimes above) those of typical hand coded Perl.
This will return a Class::MOP::Class instance which is related to this class.
The arguments to Class::MOP::Class::make_immutable are passed to this method, which
Class::MOP::Class::make_immutable
This method becomes read-only in an immutable class.
Stevan Little <stevan@iinteractive.com>
Yuval Kogman <nothingmuch@woobling.com>
Copyright 2006 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::MOP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::MOP
CPAN shell
perl -MCPAN -e shell install Class::MOP
For more information on module installation, please visit the detailed CPAN module installation guide.