perl - When should I make a Moose class immutable when I'm actually using ->meta? -


Normally i __ package __-> Meta-> I can finalize a class in the compilation through the make_imurable end of class. However, when I make an orbit unchanged, which plays a role on the runtime? Should I do the same to get better performance or is it incompatible with make_immutable ? make_immutable starts accelerating the acceleration of the object, but does this once when the object is installed?

For example, something on the lines of this:

  build {my $ self = shift; Module :: Load Use; ### Use the passed logic to determine the roles applied to this example ### of objects. Load and apply roles {$ load for $ my role ($ self-> _determine_roles ()); $ Role- & gt; Meta & gt; Applicable ($ self); } ### $ Self now a class :: Mop :: class :: __ ANON __... anonymous class ### Should I say then that I want to change it with something like this? Can ### create _imetubeable also run on an object instance and not a package? $ Self & gt; Meta & gt; Make_immutable; }   

What happens if the code works for a package above, even when an object automatically reboots with the 'Foo' role As a result, there is an anonymous class, so a second object blesses itself with a 'foo' (with the same annex), then the 'bar' role ? Is it going to work correctly when the second object blesses itself in an invariant previously unknown class, then trying to implement the role of the now-immutable anonymous class to create a new anonymous class?

, it appears that only one class can be immutable, not an example of the object, if so, am I making changes in my classes like ignoring make_immutable needed? "post-text" itemprop = "text">

You should do make_immutable normally below your class, and about your BUILD Do not worry about .

When you apply a role for an example in the runtime, this role does not modify the example class (it will be messy and terrible and will affect all other instances of that class ); It creates a new anonymous class that receives from your class and also makes requested roles, and then the example of that class is not being revised again because the original class is not being modified, so there is no issue that it is open / Is ineligible or not.

You can actually do do this $ self-> Meta-> gt; Make_immutable role after application ??? It will unify the newly created anonymous class and you may want to complete it but it will only give a small profit, because most make_immutable makes the constructor faster, and the new class creator Do not walk in the way.

If you want to see examples of how the application works, for example, you should peek at the source.

Comments