develooper Front page | perl.moose | Postings from August 2016

Re: Why to use Moose roles ever?

Thread Previous | Thread Next
Thomas Klausner
August 11, 2016 08:48
Re: Why to use Moose roles ever?
Message ID:

> Are there any real situations where roles are better than base classes?
> With examples, please.

I think MooseX::Storage is a nice example: You have some class (with 
whatever interitance tree), apply a generic role from CPAN, and bam! you 
can serialize your objects. Yes, you could achieve the same effect using 
plain old inheritance, but the you'd probably have to use multiple 
inheritance, which leads to all kinds of chaos (which of course can be 
managed, but why, when roles provide a cleaner solution).


for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About