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.


In reply to Re: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo by tobyink
in thread 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.