----- Original Message ---- > From: Chris Prather <[email protected]> > >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?
To summarize what I think you've said, you think that this is a bad idea: package My::Class; use Moose; with 'Does::A::Role::Which::Requires::A::Method'; promises qw( methods a role might require ); Your objection is that the method(s) might not exist at runtime, therefore making a promise which might not be kept is a bad thing. You may very well be right. Giving people the flexibility to hang themselves, though, seems to be what Perl is all about :) There are few use cases I see. First is the obvious example of another role being applied at runtime and supplying the promised method. The second is a method being provided via AUTOLOAD. I certainly don't recommend AUTOLOAD, but sometimes it's useful. Someone also might try to use SelfLoader to load methods on demand. When this happens, ->can($method) fails until we have our first method call (again, I'm unsure this would be a good idea with Moose). So while there are a number of areas in which we find that methods might not exist at composition time and implementing promises() might help, I also understand your concern and I'm not strongly wedded to this proposal, so if it doesn't make people's socks roll up and down, so be it :) Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
