When should I make the Musa class immutable, when I actually use & # 8594; meta?

I usually end the class when compiling through __PACKAGE__->meta->make_immutableat the end of the class. However, when should I make a class immutable, which creates roles in itself at runtime? Should I do this to improve performance or is it incompatible with make_immutable? make_immutableseems to speed up the creation of the object, but does it do anything after the creation of the object?

For example, something like strings:

BUILD {
  my $self = shift;
  use Module::Load;

  ### Use the arguments passed in to determine roles applicable to 
  ### this instance of the object. Load and apply roles.
  for my $role ($self->_determine_roles()) { 
    load $role;
    $role->meta->apply($self);
  }

  ### $self is now a Class::MOP::Class::__ANON__... anonymous class
  ### Should I then be saying I'm done mutating it with something like this?
  ### can make_immutable even be run on an object instance and not a package?
  $self->meta->make_immutable;
}

, , 'Foo', , 'Foo' ( anon ), 'Bar' ? , , ?

Moose:: Meta:: Class, , , . , make_immutable, ?

+5
1

make_immutable, , , BUILD.

, ( ); , , . , / .

$self->meta->make_immutable - - - , , . , , make_immutable , - , .

, - , Moose::Meta::Role::Application::ToInstance.

+7

All Articles