in reply to Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
Forget HandlesVia for now and consider this:
my @toppings = ( FishTaco::Topping->new ); my $ft = FishTaco->new( _toppings => \@toppings ); push @toppings, "OHAI";
You can push stuff onto the array without Moo checking that the stuff you're pushing makes any sense. This is because it only checks the array is valid in the constructor and in non-read-only attribute accessors. The exact same happens with Moose.
Moose native traits give you the handles stuff for arrays, and Moose is smart enough to add type checking to push when you do this. MooX::HandlesVia is not quite so smart. (This is partly due to limitations in how Moo works.)
Now try this:
my @toppings = ( FishTaco::Topping->new ); tie @toppings, InstanceOf['FishTaco::Topping']; my $ft = FishTaco->new( _toppings => \@toppings ); push @toppings, "OHAI"; # this should die
Yay?
Now play around with trigger.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
by Your Mother (Archbishop) on May 01, 2019 at 03:43 UTC | |
by tobyink (Canon) on May 01, 2019 at 10:49 UTC | |
by Your Mother (Archbishop) on May 01, 2019 at 18:35 UTC | |
by tobyink (Canon) on May 03, 2019 at 13:23 UTC |