in reply to Class capabilities

It doesn't sound like you're not duck-typing so much as looking for interfaces (or P6 roles). You're not looking for can() so much as provides (from Java) or does (from P6 et al). can() is too fragile.

Without the OO Metamodel that stvn is writing, there's no simple way that I know of in P5 to publish that you provide a given interface. Solving this in a perlish way would be a neat thing to do.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Class capabilities
by Ovid (Cardinal) on Oct 12, 2005 at 06:11 UTC

    You do raise some good points. I do think the Params::Validate suggestion is the best so far (I always forget about that module), but I do sort of like the idea of a module published which states explicitly that it depends on the can() method properly functioning (meaning that if AUTOLOAD or something similar is being used that can should be overridden). Too often we let ourselves get sloppy and forget little details like that.

    Cheers,
    Ovid

    New address of my CGI Course.

      A quick CPAN search for "interface" brings up the interface module. That looks promising. It references Class::Contract, which may be a little too much koolaid for you, but it would definitely do what you're looking for. :-)

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?