From: 大沢 和宏 Date: Tue, 2 Dec 2008 15:44:06 +0000 (+0000) Subject: added to coerce moose compat test case X-Git-Tag: 0.19~136^2~80 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c40a22570a1412a4c442f5c64a56d8c5a7e688c;p=gitmo%2FMouse.git added to coerce moose compat test case --- diff --git a/t/501_moose_coerce_mouse.t b/t/501_moose_coerce_mouse.t new file mode 100644 index 0000000..68c420f --- /dev/null +++ b/t/501_moose_coerce_mouse.t @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use t::Exception; +BEGIN { + plan skip_all => "Moose required for this test" unless eval { require Moose && Moose->VERSION('0.59') }; + plan tests => 5; +} + +use t::Exception; + +{ + package Headers; + use Mouse; + has 'foo' => ( is => 'rw' ); +} +{ + package Response; + use Mouse; + use Mouse::TypeRegistry; + + subtype 'HeadersType' => sub { defined $_ && eval { $_->isa('Headers') } }; + coerce 'HeadersType' => +{ + HashRef => sub { + Headers->new(%{ $_ }); + }, + }; + + has headers => ( + is => 'rw', + isa => 'HeadersType', + coerce => 1, + ); +} +{ + package Mosponse; + use Moose; + extends qw(Response); + ::lives_ok { extends qw(Response) } "extend Mouse class with Moose"; +} + +{ + my $r = Mosponse->new(headers => { foo => 'bar' }); + local our $TODO = "Moose not yet aware of Mouse meta"; + isa_ok($r->headers, 'Headers'); + is(eval{$r->headers->foo}, 'bar'); + $r->headers({foo => 'yay'}); + isa_ok($r->headers, 'Headers'); + is($r->headers->foo, 'yay'); +}