Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why to use Moose roles ever?

0 views
Skip to first unread message

Victor Porton

unread,
Aug 10, 2016, 9:15:01 AM8/10/16
to mo...@perl.org
Moose roles have some limitations, such as inability to override a
method in a class which "with"es the role.

But I can use an abstract base class instead of a role.

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

Thomas Klausner

unread,
Aug 11, 2016, 5:00:02 AM8/11/16
to mo...@perl.org
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$_.$/}
0 new messages