elTriberium has asked for the wisdom of the Perl Monks concerning the following question:
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).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Inherit from a Role (or something like that)
by John M. Dlugosz (Monsignor) on May 20, 2011 at 20:07 UTC | |
by elTriberium (Friar) on May 20, 2011 at 20:44 UTC | |
by John M. Dlugosz (Monsignor) on May 20, 2011 at 23:37 UTC | |
by elTriberium (Friar) on May 21, 2011 at 00:15 UTC | |
by John M. Dlugosz (Monsignor) on May 21, 2011 at 12:41 UTC |