From: gfx Date: Fri, 12 Feb 2010 12:57:37 +0000 (+0900) Subject: Add tests for traits X-Git-Tag: 0.50_01~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=668f695d6889ac6ac523025f39f2306195f2f3b0;p=gitmo%2FMouse.git Add tests for traits --- diff --git a/t/001_mouse/067-traits.t b/t/001_mouse/067-traits.t new file mode 100644 index 0000000..97c79e8 --- /dev/null +++ b/t/001_mouse/067-traits.t @@ -0,0 +1,77 @@ +#!perl +use strict; +use warnings; + +use Test::More; + +use Test::Mouse qw(does_ok); + +BEGIN{ + package MyMouseX::Foo::Method; + use Mouse::Role; + + sub foo {} + + package MyMouseX::Bar::Method; + use Mouse::Role; + + sub bar {} + + package MyMouseX::Foo; + use Mouse::Exporter; + use Mouse::Util::MetaRole; + + Mouse::Exporter->setup_import_methods( + also => 'Mouse', + ); + sub init_meta { + my(undef, %options) = @_; + + my $meta = Mouse->init_meta(%options); + Mouse::Util::MetaRole::apply_metaroles( + for => $options{for_class}, + class_metaroles => { + method => ['MyMouseX::Foo::Method'], + }, + ); + } + + $INC{'MyMouseX/Foo.pm'} = __FILE__; + + package MyMouseX::Bar; + use Mouse::Exporter; + use Mouse::Util::MetaRole; + + Mouse::Exporter->setup_import_methods( + also => 'Mouse', + ); + sub init_meta { + my(undef, %options) = @_; + + my $meta = Mouse->init_meta(%options); + Mouse::Util::MetaRole::apply_metaroles( + for => $options{for_class}, + class_metaroles => { + method => ['MyMouseX::Bar::Method'], + }, + ); + } + + $INC{'MyMouseX/Bar.pm'} = __FILE__; +} +{ + package ClassA; + use MyMouseX::Foo; + + sub a {} + + package ClassB; + use MyMouseX::Bar; + + sub b {} +} + +does_ok(ClassA->meta->get_method('a'), 'MyMouseX::Foo::Method'); +does_ok(ClassB->meta->get_method('b'), 'MyMouseX::Bar::Method'); + +done_testing;