NAME
MooseX::Interface - Java-style interfaces for Moose
SYNOPSIS
package DatabaseAPI::ReadOnly
{
use MooseX::Interface;
requires 'select';
}
package DatabaseAPI::ReadWrite
{
use MooseX::Interface;
extends 'DatabaseAPI::ReadOnly';
requires 'insert';
requires 'update';
requires 'delete';
}
package Database::MySQL
{
use Moose;
with 'DatabaseAPI::ReadWrite';
sub insert { ... }
sub select { ... }
sub update { ... }
sub delete { ... }
}
Database::MySQL::->DOES('DatabaseAPI::ReadOnly'); # true
Database::MySQL::->DOES('DatabaseAPI::ReadWrite'); # true
DESCRIPTION
MooseX::Interface provides something similar to the concept of interfaces as found in many object-oriented programming languages like Java and PHP.
"What?!" I hear you cry, "can't this already be done in Moose using roles?"
Indeed it can, and that's precisely how MooseX::Interface works. Interfaces are just roles with a few additional restrictions:
You may not define any methods within an interface, except:
You may not define any attributes. (Attributes generate methods.)
You may not define method modifiers.
You can extend other interfaces, not normal roles.
Functions
extends $interface
-
Extends an existing interface.
Yes, the terminology "extends" is used rather than "with".
excludes $role
-
Prevents classes that implement this interface from also composing with this role.
requires $method
-
The name of a method (or attribute) that any classes implementing this interface must provide.
A future version of MooseX::Interface may provide a way to declare method signatures.
const $name => $value
-
Experimental syntactic sugar for declaring constants. It's probably not a good idea to use this yet.
BUGS
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-Interface.
SEE ALSO
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
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.
DISCLAIMER OF WARRANTIES
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.