---
name: "Class::MOP::Class::Immutable"
section: "3pm"
platform: "linux"
package: "libclass-mop-perl"
version: "0.36-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/Class::MOP::Class::Immutable"
---

# Class::MOP::Class::Immutable(3pm)

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.\
 **Introspection and Construction** The arguments to `"Class::MOP::Class::make_immutable"` are passed  to this method, which \
 **Methods which will die if you touch them.**\
 **Methods which work slightly differently.** This method becomes read-only in an immutable class.\
 **Cached methods** 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.
