A hash table is a typical initializer for your Perl objects. Now your input is unreliable because you do not know if there will be a certain value for any given key, or if there will be no key at all. Now you want to feed such an unreliable entry into Moose objects, and while the missing keys are fine, you want to get rid of undefined values ββso that you don't end up with an object full of undefined attributes.
You could be very careful when creating objects and filtering undefined values. But let's say you want to install this filter in your constructor, because it is in one place. You want the constructor to ignore undefined values, but not die when it encounters them.
For access methods, you can use around to prevent the attribute from being set to undef . But those methods method modifiers are not called for the constructor, only for accessories. Is there a similar tool in Muse to achieve the same effect for c'tor, i.e. To prevent the adoption of any undef attributes?
Note that the Moose Any type will create a hash key in the object if the attribute is undef. I do not want this because I want %$self not contain any undef values.
Here are some tests I have done:
package Gurke; use Moose; use Data::Dumper; has color => is => 'rw', isa => 'Str', default => 'green'; has length => is => 'rw', isa => 'Num'; has appeal => is => 'rw', isa => 'Any'; around color => sub {
Lumi
source share