Benchmark-DKbench
view release on metacpan or search on metacpan
data/t/attributes/attribute_does.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{
package Foo::Role;
use Moose::Role;
use Moose::Util::TypeConstraints;
# if does() exists on its own, then
# we create a type constraint for
# it, just as we do for isa()
has 'bar' => (is => 'rw', does => 'Bar::Role');
has 'baz' => (
is => 'rw',
does => role_type('Bar::Role')
);
package Foo::Class;
use Moose;
with 'Foo::Role';
package Bar::Role;
use Moose::Role;
# if isa and does appear together, then see if Class->does(Role)
# if it does work... then the does() check is actually not needed
# since the isa() check will imply the does() check
has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role');
package Bar::Class;
use Moose;
with 'Bar::Role';
}
my $foo = Foo::Class->new;
isa_ok($foo, 'Foo::Class');
my $bar = Bar::Class->new;
isa_ok($bar, 'Bar::Class');
is( exception {
$foo->bar($bar);
}, undef, '... bar passed the type constraint okay' );
isnt( exception {
$foo->bar($foo);
}, undef, '... foo did not pass the type constraint okay' );
is( exception {
$foo->baz($bar);
}, undef, '... baz passed the type constraint okay' );
isnt( exception {
$foo->baz($foo);
}, undef, '... foo did not pass the type constraint okay' );
is( exception {
$bar->foo($foo);
}, undef, '... foo passed the type constraint okay' );
( run in 2.487 seconds using v1.01-cache-2.11-cpan-54e63673c56 )