p5-object-role / t / 02methodinstallation.t

use Test::More tests => 10;

	package Local::MyRole;
	use base qw/Object::Role/;
	sub import
		my ($class,  @args) = @_;
		my ($caller, %args) = __PACKAGE__->parse_arguments(@args);
		__PACKAGE__->install_method(somefunc => sub{1}, $caller);

	package Local::MyClass;
	BEGIN { Local::MyRole->import }
	sub new { bless \@_, shift }

	package main;
	my $obj = Local::MyClass->new;
	ok(Local::MyRole->isa('Object::Role'), 'Local::MyRole isa Object::Role');
	ok(!Local::Class->isa('Object::Role'), 'NOT Local::MyClass isa Object::Role');
	ok(Local::MyRole->has_consumer('Local::MyClass'), 'Local::MyRole has_consumer Local::MyClass');
	ok(!Local::MyRole->has_consumer('base'), 'NOT Local::MyRole has_consumer base');
	ok(!Local::MyRole->has_consumer('Object::Role'), 'NOT Local::MyRole has_consumer Object::Role');
	ok(!Local::MyRole->has_consumer('Local::MyRole'), 'NOT Local::MyRole has_consumer Local::MyRole');
	ok(!Local::MyRole->can('somefunc'), 'NOT Local::MyRole can somefunc');
	ok(Local::MyClass->can('somefunc'), 'Local::MyClass can somefunc');
	ok($obj->can('somefunc'), 'Local::MyClass instance can somefunc');
	ok($obj->somefunc, 'somefunc works');
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.