Often you want to create components that can be added to a class arbitrarily. This module makes it easy for the end user to use these components. Instead of requiring the user to create a named class with the desired roles applied, or apply roles to the instance one-by-one, he can just create a new class from yours with 'with_traits', and then instantiate that.
There is also 'new_with_traits', which exists for compatibility reasons. It accepts a 'traits' parameter, creates a new class with those traits, and then instantiates it.
Class->new_with_traits( traits => [qw/Foo Bar/], foo => 42, bar => 1 )
returns exactly the same object as
Class->with_traits(qw/Foo Bar/)->new( foo => 42, bar => 1 )
would. But you can also store the result of 'with_traits', and call other methods:
my $c = Class->with_traits(qw/Foo Bar/); $c->new( foo => 42 ); $c->whatever( foo => 1234 );
And so on.
Package Version | Update ID | Released | Package Hub Version | Platforms | Subpackages |
---|---|---|---|---|---|
0.13-bp156.3.1 info | GA Release | 2023-07-22 | 15 SP6 |
|
|
0.13-bp155.2.8 info | GA Release | 2023-05-17 | 15 SP5 |
|
|
0.13-bp154.1.17 info | GA Release | 2022-05-09 | 15 SP4 |
|
|
0.13-bp153.1.13 info | GA Release | 2021-03-06 | 15 SP3 |
|
|
0.13-bp152.3.13 info | GA Release | 2020-04-17 | 15 SP2 |
|
|
0.13-bp151.3.1 info | GA Release | 2019-07-16 | 15 SP1 |
|
|
0.13-bp151.2.11 info | GA Release | 2019-05-18 | 15 SP1 |
|
|
0.13-bp150.2.4 info | GA Release | 2018-07-30 | 15 |
|
|