3 use Test::More tests => 6;
8 has 'foo' => ( is => 'rw' );
14 use Mouse::Util::TypeConstraints;
16 subtype 'HeadersType' => as 'Object' => where { defined $_ && eval { $_->isa('Headers') } };
17 coerce 'HeadersType' =>
18 from 'ScalarRef' => via {
21 from 'HashRef' => via {
22 Headers->new(%{ $_ });
31 has lazy_build_coerce_headers => (
37 sub _build_lazy_build_coerce_headers {
38 Headers->new(foo => 'laziness++')
40 has lazy_coerce_headers => (
45 default => sub { Headers->new(foo => 'laziness++') }
49 my $r = Response->new(headers => { foo => 'bar' });
50 isa_ok($r->headers, 'Headers');
51 is($r->headers->foo, 'bar');
52 $r->headers({foo => 'yay'});
53 isa_ok($r->headers, 'Headers');
54 is($r->headers->foo, 'yay');
55 is($r->lazy_coerce_headers->foo, 'laziness++');
56 is($r->lazy_build_coerce_headers->foo, 'laziness++');