On Mon, Jun 22, 2009 at 8:51 AM, Ovid<publiustemp-catal...@yahoo.com> wrote: > The is_xml() method was merely an example. The key issue is actually more > general. If a role requires a class provide a given method but the method > is not available until an instance in instantiated, requires() doesn't work. > > Or have I misunderstood you? I only skimmed MooseX::Storage.
I didn't see the focus because you're description was so similar to MooseX::Storage (which is a more generic Serialiation than XML). That said afaik currently methods are only composed at the Class level. Moose's Role application to Instances create an anonymous subclass, apply the role to the anonymous subclass, and then rebless the instance into that subclass. In your example you wouldn't have an instance that is blessed into a class that lacks an as_xml method, if you did and composed the Role against it you would *want* that composition to choke. You seem to be trying to make contractual obligations for Runtime at Compile time, but I think you're doing it poorly here. The promises() keyword here doesn't resolve the fact that the method *might not* exist at runtime, at which point we want the composition to fail, all it does is let us do an end-run around what is effectively a Runtime operation (applying a Role to an instance) so we can do it at compile time instead ... what's the benefit here? -Chris