Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: Moose role with requirement consuming another role

by Arunbear (Parson)
on Jul 21, 2011 at 10:53 UTC ( #915830=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Moose role with requirement consuming another role
in thread Moose role with requirement consuming another role

In a Java-like language, an abstract base class is often used to provide functionality (often mandated by some interface) to classes that inherit from it, but it cannot be used/instantiated on its own. "abstract" means that it can't be instantiated, it doesn't mean that it provides no functionality.

This is how you are using Role::App. It is like an an abstract base class in the sense that it can't be instantiated and it provides functionality to App::FixIt. Some of that functionality is mandated by Role::Logger. What the docs are saying is that mandated methods have to be supplied in classes not in roles.


Comment on Re^5: Moose role with requirement consuming another role
Re^6: Moose role with requirement consuming another role
by Boldra (Deacon) on Jul 21, 2011 at 11:12 UTC
    Ok, then it's clear we are using a different definitions of "abstract base class". You include classes which provide functionality in your definition, I do not. I don't think the Moose documentation you referenced supports your usage.



    - Boldra
      The documentation I referenced does not define an abstract base class, it only says
      "If you are familiar with the concept of abstract base classes in other languages, you may be tempted to use roles in the same way."
      Since Java is one of those languages that has an abstract base class concept (as well as a mechanism for mandating that certain methods are implemented), I have been referring to the Java style of abstract base classes.

      If the documentation doesn't support this usage, then which usage do you think it supports?

        You're right, I was confusing "abstract base class" with "interface role".

        That documentation mainly talks about interface roles, but in the sentence "Because the role defines the required methods directly, adding a base class to the mix would not achieve anything" presumably refers to the fact that class<-(role or abstract class)<-interface-role won't work if you only meet your interface-role requirements in the child class. "base class" in that sentence should probably be "abstract class or role". The document is really warning that you should instead use class<-interface-role plus class<-(role or abstract class).

        Now if I've understood that correctly, it's still a not explaining the behavior which I'm seeing. If both has and with are evaluated at runtime and not compile-time, putting them in the correct order should mean that a role can fulfill requirements set by another role, with either a subroutine or a Moose attribute, and not only with a subroutine. I don't care that we veered off-topic, because this taught me something, so thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://915830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-07-26 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls