Your Mother has asked for the wisdom of the Perl Monks concerning the following question:
Using Types::Standard, MooX::HandlesVia, and Moo–
#!/usr/bin/env perl { package FishTaco::Topping; use Moo; } { package FishTaco; use Moo; use MooX::HandlesVia; use Types::Standard qw( ArrayRef InstanceOf ); has _toppings => is => "rw", isa => ArrayRef[ InstanceOf['FishTaco::Topping'] ], default => sub { [] }, handles_via => "Array", handles => { add_topping => "push", toppings => "elements", }; } use strictures; use Path::Tiny; use Scalar::Util "blessed"; my $ft = FishTaco->new; $ft->add_topping( FishTaco::Topping->new ); # Sure. $ft->add_topping( path("/") ); # Wrong object type. $ft->add_topping( "OHAI" ); # Not even an object. print blessed($_) || "[n/a]", $/ for $ft->toppings; __END__ FishTaco::Topping Path::Tiny [n/a]
–but I expect the latter two calls to add_topping to throw an error since they “break” the isa of ArrayRef[ InstanceOf['FishTaco::Topping'] ]. I’m sure I’m doing something wrong or misunderstanding, but what? :P
(Update: title was badly worded.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble or misunderstand of Types::Standard ArrayRef[elements] enforcement in Moo
by choroba (Cardinal) on Apr 28, 2019 at 20:30 UTC | |
|
Re: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
by tobyink (Canon) on Apr 30, 2019 at 17:59 UTC | |
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 |