Types::Interface - fuzzy role constraints
package MyApp::Role::FooBar { use Moose::Role; requires qw( foo bar ); } package MyApp::Class::FooBar { use Moose; # Note, the following line is commented out! # with qw( MyApp::Role::FooBar ); sub foo { 1 } sub bar { 2 } } package MyApp::Class::Main { use Moose; use Types::Interface qw(ObjectDoesInterface); has foobar => ( is => 'ro', isa => ObjectDoesInterface['MyApp::Role::FooBar'], ); } # This is ok... my $obj = MyApp::Class::Main->new( foobar => MyApp::Class::FooBar->new(), );
Types::Interface provides a type constraint library suitable for Moose, Mouse, and Moo attributes, Kavorka signatures, and any other place where type constraints might be used.
The type constraints it provides are based on the idea that an object or class might fulfil all the requirements for a role without explicitly consuming the role.
This module provides the following type constraints:
ObjectDoesInterface[$role]
This type constraint accepts any object where $object->DOES($role) returns true, or where the object happens to provide all the methods that form part of the role's API, according to Role::Inspector.
$object->DOES($role)
This type constraint is a subtype of Object from Types::Standard.
Object
ObjectDoesInterface[$role, private => 0]
This type constraint accepts any object where $object->DOES($role) returns true, or where the object happens to provide all the public methods (i.e. those not starting with an underscore) that form part of the role's API, according to Role::Inspector.
ClassDoesInterface[$role]
This type constraint accepts any class name where $class->DOES($role) returns true, or where the class happens to provide all the methods that form part of the role's API, according to Role::Inspector.
$class->DOES($role)
This type constraint is a subtype of LoadableClass from Types::LoadableClass.
LoadableClass
ClassDoesInterface[$role, private => 0]
This type constraint accepts any class name where $class->DOES($role) returns true, or where the object class to provide all the public methods (i.e. those not starting with an underscore) that form part of the role's API, according to Role::Inspector.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Types-Interface.
Type::Tiny::Manual, Types::LoadableClass, Types::Standard, Role::Inspector.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2014 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 Types::Interface, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Types::Interface
CPAN shell
perl -MCPAN -e shell install Types::Interface
For more information on module installation, please visit the detailed CPAN module installation guide.