If you wrote UNIVERSAL::implements and made it take a contract name, you'd have what you want. I think I'm more likely to use Params::Validate to do my duck-type checking. Not that it's seemed all that important in practice. Occasionally I've needed ->can() and if the object has a method of the appropriate name, that's good enough. I've never seen an occasion where an object implements something wrong under the same name.
Normal duck typing
use Params::Validate 'validate_pos'; use constant FOOBAR_TYPE => { can => [ qw[ print flush frobnicate ] ] +}; sub bar { my $foobar = validate_pos( @_, FOOBAR_TYPE ); }
Your stricter version.
use Params::Validate 'validate_pos'; use constant FOOBAR_TYPE => { callbacks => { interface => sub { Interf +ace::has( FooBar => $_[0] ) } } }; sub bar { my $foobar = validate_pos( @_, FOOBAR_TYPE ); } package FooBar; use Interface 'FOOBAR'; ...
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re^3: Interfaces for the masses!
by diotalevi
in thread Interfaces for the masses!
by rvosa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |