MooseX::Interface::Tutorial - random thoughts that might one day become a proper tutorial
Here's a good way of using interfaces. Rather than saying that your website's logger must be an instance of a particular class (isa), specify an interface that the object must implement (does).
isa
does
The object can be tested against the interface at run time.
package Website { use Moose; has logger => ( is => 'ro', does => 'Website::LoggerAPI', ); sub BUILD { my $self = shift; Website::LoggerAPI->meta->test_implementation($self->logger) or confess "logger does not implement Website::LoggerAPI"; } ...; } package Website::LoggerAPI { use MooseX::Interface; requires 'log_message'; test_case { ... }; }
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-Interface.
MooseX::Interface.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::Interface, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Interface
CPAN shell
perl -MCPAN -e shell install MooseX::Interface
For more information on module installation, please visit the detailed CPAN module installation guide.