On Wed, 9 Apr 2014, Thalhammer, Jeffrey Ryan wrote:
I've begun using Roles to declare interfaces -- that is, nothing more than a list of "requires". So let's say I have a Role that requires 15 attributes/methods. In the implementation, I know that 5 of those will be delegated to one class, 5 delegated to another, and the other 5 implemented by the consuming class.
From memory, consume the interface/interface-role after all other declarations and role consumption, e.g.
package Moosy; use Moose; extends 'bar'; with 'meh'; require 'blah'; require 'blah2'; __PACKAGE__->meta->make_immutable(); 1; As long as the implementation methods already exist at the point of requiring them, everything is golden. However, declaring them all at the *end* of a package just before make_immutable(); 1; makes things too hidden and unintuitive for my liking. I like MooseX::Declare's approach where they're all applied at the end but declared up top within the class {} declaration, but you still need to get the order of consumption right - implementations before interfaces. But once you've got it, you can $object->does('My::Interface::Blah') which is pretty important if, like me, you want to start depending on abstractions and interfaces rather than concretions. It's worth pursuing imho, but an improved implementation even full Traits support would be ideal.
Can you suggest a good way to handle this? Or maybe convince me that I'm doing it all wrong anyway?
The code above may not compile, but that's roughly what I discovered and how I learnt to work around it. Yell if it doesn't work and you need more help and I'll put out some real code. -- Niall Young ni...@iinet.net.au