Hi Monks,

I'm still struggling a bit with the Moose concept of Roles. I'm trying to solve a specific problem here, but can't figure out how to do it with Moose.

In this project we have a Role "RemoteConnection" which is added to 2 modules: "SSH" and "Socket" to provide access to remote resources. Based on a configuration option we want to chose during runtime whether we're using an SSH or Socket connection.

We also have multiple derived modules, e.g. "Server" and "Client" that. I want to write those modules only against the interface defined in the RemoteConnection role, so that I can easily exchange SSH by Socket and vice-versa whenever needed. The application will then create a Server or Client object and will be able to run stuff on that resource without having to care whether this is an SSH or Socket connection. I already defined the role and this is added into the 2 modules, but now how do I write my other classes against this role?

I thought about a few solutions, but none fulfils all the requirements: I thought about using a factory which creates either a SSH or Socket object, but then I can't easily inherit from both of them in Server and Client.

Inheritance is needed because the child classes have to overwrite some attributes and methods of the parent class(es).


In reply to Inherit from a Role (or something like that) by elTriberium

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.