The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::MOP::Class::Immutable - An immutable version of Class::MOP::Class

SYNOPSIS

  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

DESCRIPTION

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.

METHODS

meta

This will return a Class::MOP::Class instance which is related to this class.

Introspection and Construction

make_metaclass_immutable

The arguments to Class::MOP::Class::make_immutable are passed to this method, which

inline_accessors (Bool)
inline_constructor (Bool)
debug (Bool)
constructor_name (Str)
is_immutable
is_mutable
make_immutable
get_mutable_metaclass_name

Methods which will die if you touch them.

add_attribute
add_method
add_package_symbol
alias_method
remove_attribute
remove_method
remove_package_symbol

Methods which work slightly differently.

superclasses

This method becomes read-only in an immutable class.

Cached methods

class_precedence_list
compute_all_applicable_attributes
get_meta_instance
get_method_map

AUTHORS

Stevan Little <stevan@iinteractive.com>

Yuval Kogman <nothingmuch@woobling.com>

COPYRIGHT AND LICENSE

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.