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.)


In reply to Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo by Your Mother

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.