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

Re: Why to use Moose roles ever?

Thread Previous | Thread Next
From:
Thomas Klausner
Date:
August 11, 2016 08:48
Subject:
Re: Why to use Moose roles ever?
Message ID:
20160811084806.GJ31830@plix.at
Hi!

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

https://metacpan.org/pod/MooseX::Storage

Greetings,
domm

-- 
#!/usr/bin/perl                              http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About