Hi all,

This might be a rather stupid idea.  Plus, it's something I could see people 
preferring in a MooseX package instead.

When creating a role, we often provide a list of requirements:

  package Does::Serialization::YAML;

  use Moose::Role;
  requires 'as_xml';

The problem here is that requires() acts on the class level, but sometimes we 
need it to act on the instance level and I might not have an as_xml() method 
until I have an instance which which knows which 'as_xml()l method to supply 
(i.e., we might have different request-dependent xml formats).  Thus, we could 
potentially have this:

  package My::Customer;
  use Moose;
  with 'Does::Serialization::YAML';
  promises qw(as_xml);

promises() would only be useful (that I can think of) in the context of 
satisfying role requirements.  I'm unsure of exactly how this would work with 
method modifiers such as 'before', 'around', etc., but I imagine one could do 
something like this:

  my $coderef = $class->promises('as_xml');

And when the coderef is invoked (lazily) at runtime, it invokes the actual 
as_xml() code or throws an exception if it's not been installed.


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

Reply via email to