How does immutability in Moose affect performance or memory usage?

immutability, Moose, performance, memory usage, Perl, object-oriented programming
This article discusses how immutability in Moose affects performance and memory usage in Perl, providing insights into best practices for optimizing your applications.

package MyImmutableClass;
use Moose;
use Moose::Util::TypeConstraints;

# Define an immutable class
use MooseX::Immutable;
has 'name' => ( is => 'ro', required => 1 );
has 'age'  => ( is => 'ro', required => 1 );

# Usage
my $instance = MyImmutableClass->new( name => 'John', age => 30 );

# Attempting to modify an attribute will cause an error
# $instance->name('Doe'); # This line will throw a runtime error
    

immutability Moose performance memory usage Perl object-oriented programming