Re: Why to use Moose roles ever?
[email protected] (Niall Young) Thu, 11 Aug 2016 13:43:40 +1000 (AEST)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
--0-260667862-1470887022=:88165
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8BIT
On Wed, 10 Aug 2016, Victor Porton wrote:
> 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.
I was going to suggest augment'ing a method in a Role, which I'd been planning to explore as a way of declaring interfaces and standard parameter/type checks in Classes, while consuming Roles for the implementation, but alas:
"Roles cannot support 'augment' at ..."
> This is false. For example:
Not sure how your example applies here Karen, there is no foo() declared in MyClass only a foo method modifier, and MyRole's foo() doesn't appear to be executed from your output?
> package MyClass;
> use Moose;
> with 'MyRole';
> around foo => sub {
> 'I came from the class';
> };
> say $obj->foo;
> # prints: I came from the class
--
Niall Young
[email protected]
--0-260667862-1470887022=:88165--