Source

p5-scalar-does / t / 03moosey.t

use Test::More;

BEGIN {
	eval { require Moose; require MooseX::Types::Moose; 1 }
		or plan skip_all => "needs Moose and MooseX::Types::Moose";
}

use Scalar::Does;
use MooseX::Types::Moose -all;

ok(
	does(12, Num),
	'12 does Num',
);
ok(
	!does('12b', Num),
	"12b doesn't Num",
);

my $union = Num | ArrayRef[Num];

ok(
	does(12, $union),
	'12 does custom type',
);
ok(
	does([qw(1 2 3)], $union),
	'[1,2,3] does custom type',
);
ok(
	!does([qw(a b c)], $union),
	'[a,b,c] doesn\'t custom type',
);
ok(
	!does(+{}, $union),
	'hashref doesn\'t custom type',
);

{
	package Local::Foo;
	use Moose::Role;
}

{
	package Local::Bar;
	use Moose;
	with 'Local::Foo';
}

{
	package MyLib;
	use MooseX::Types -declare => ['IsBar', 'DoesFoo'];
	role_type DoesFoo, { role => 'Local::Foo' };
	class_type IsBar, { class => 'Local::Bar' };
}

my $obj = Local::Bar->new;
ok(does $obj, Any);
ok(does $obj, Object);
ok(does $obj, 'UNIVERSAL');
ok(does $obj, 'Moose::Object');
ok(does $obj, 'Local::Foo');
ok(does $obj, 'Local::Bar');
ok(does $obj, MyLib::IsBar);
ok(does $obj, MyLib::DoesFoo);

done_testing();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.