From: Ash Berlin Date: Wed, 23 Jan 2008 10:59:36 +0000 (+0000) Subject: (failing) test for runtime roles and non-moose classes + does attrs X-Git-Tag: 0_36~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6ff1f9eb814f8374784f501b2e3a3085b0ccf9d;p=gitmo%2FMoose.git (failing) test for runtime roles and non-moose classes + does attrs --- diff --git a/t/030_roles/016_runtime_roles_and_nonmoose.t b/t/030_roles/016_runtime_roles_and_nonmoose.t new file mode 100644 index 0000000..706018d --- /dev/null +++ b/t/030_roles/016_runtime_roles_and_nonmoose.t @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 7; +use Test::Exception; +use Scalar::Util 'blessed'; + +BEGIN { + use_ok('Moose'); +} + + +{ + package Dog; + use Moose::Role; + + sub talk { 'woof' } + + package Foo; + use Moose; + + has 'dog' => ( + is => 'rw', + does => 'Dog', + ); + + no Moose; + + package Bar; + + sub new { + return bless {}, shift; + } +} + +my $obj = Bar->new; +isa_ok($obj, 'Bar'); + +my $foo = Foo->new; + +ok(!$obj->can( 'talk' ), "... the role is not composed yet"); + +dies_ok { + $foo->dog($obj) +} '... and setting the accessor fails (not a Dog yet)'; + +Dog->meta->apply($obj); + +ok($obj->can('talk'), "... the role is now composed at the object level"); + +is($obj->talk, 'woof', '... got the right return value for the newly composed method'); + +lives_ok { + $foo->dog($obj) +} '... and setting the accessor is okay'; +