How has support for object construction and new changed across recent Perl versions?

In recent versions of Perl, particularly from 5.6 to 5.32, there have been significant updates to object construction and the usage of the built-in `new` method for creating object instances. The `new` method is traditionally associated with object-oriented programming in Perl, allowing for cleaner and more encapsulated code.

Initially, the `new` method was used as a class constructor that would typically bless a reference into a class. This still holds true today but with numerous enhancements over the years, including better support for the `Moose` object system, which facilitates modern Perl object construction with features like roles, attributes, and type constraints.

These enhancements have made it easier to create complex object hierarchies, improve code reuse, and maintain type safety, making Perl a more robust object-oriented programming language.

Here is a simple example showing how to create a class and use the `new` method to instantiate an object:

package MyClass; sub new { my ($class, $value) = @_; my $self = bless { value => $value }, $class; return $self; } sub get_value { my $self = shift; return $self->{value}; } my $obj = MyClass->new(42); print $obj->get_value();

Perl object-oriented programming constructors object construction Moose class instance bless