I noticed this in the change in behavior:

 * Roles can now override methods from other roles they consume directly,
    without needing to manually exclude them (just like classes can). (mst)

Have there been issues reported as a result of the previous behavior of roles?


In the paper "Traits, a formal model" (which is actually rather easy to read 
and I highly recommend it - 
http://scg.unibe.ch/archive/papers/Scha02cTraitsModel.pdf), the very first 
proposition (cunningly named Proposition 1) guarantees that "Symmetric 
composition is associative and commutative." This was intended to be one of the 
strengths of traits vis-a-vis inheritance and mixins. There are already a few 
cases in Moose where this no longer holds (some of which may have been 
oversights), but now we're even more clearly discarding the associative 
guarantee. 

So the following code will print 'c' (previously it was a fatal error requiring 
the dev to state exactly what they intended):

    use 5.01000;
    { package a; use Moose::Role; sub result { 'a' } }
    { package b; use Moose::Role; }
    { package c; use Moose::Role; with qw(a b); sub result { 'c' } }
    { package d; use Moose::Role; with qw(c); }
    {
        package Consumer; use Moose;
        with 'd';
    }
    say Consumer->new->result;

And this will print 'a', even though the class is consuming what appears to be 
the same role:

    use 5.01000;
    { package a; use Moose::Role; sub result { 'a' } }
    { package b; use Moose::Role; }
    { package c; use Moose::Role; with qw(a b); sub result { 'c' } }
    { package d; use Moose::Role; with qw(c); }
    {
        package Consumer; use Moose;
        with 'd';
    }
    say Consumer->new->result;

Note that in the above examples, I have changed nothing but the order in which 
the roles are consumed, but my behavior has changed.

The associative and commutative guarantees are the primary mechanism that 
traits use to overcome the limitations of MI and mixins. I should be able to 
mix-and-match my roles at will without worrying about breaking my contract with 
the consumer.

Cheers,
Ovid
--
Twitter - http://twitter.com/OvidPerl/
Buy my book - http://bit.ly/beginning_perl
Buy my other book - http://www.oreilly.com/catalog/perlhks/
Live and work overseas - http://www.overseas-exile.com/


>________________________________
> From: Karen Etheridge <p...@froods.org>
>To: moose@perl.org 
>Sent: Thursday, 28 March 2013, 16:11
>Subject: Announcement: Moose 2.0800 is released!
> 
>
>Moose-2.0800 has been uploaded.  Enjoy!
>
>https://metacpan.org/source/ETHER/Moose-2.0800/Changes
>
>
>-- 
>             "Society is like a stew. If you don't keep it stirred
>             up you get a lot of scum on the top." - Edward Abbey
>            .             .            .            .             .
>Karen Etheridge, ka...@etheridge.ca       GCS C+++$ USL+++$ P+++$ w--- M++
>
>
>

Reply via email to