We only need local $? if we inline calls to DEMOLISH
[gitmo/Moose.git] / t / attributes / misc_attribute_coerce_lazy.t
CommitLineData
d7611a4a 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
d7611a4a 8
7ff56534 9
d7611a4a 10
11{
12 package HTTPHeader;
13 use Moose;
d03bd989 14
d7611a4a 15 has 'array' => (is => 'ro');
d03bd989 16 has 'hash' => (is => 'ro');
d7611a4a 17}
18
19{
20 package Request;
21 use Moose;
22 use Moose::Util::TypeConstraints;
d03bd989 23
24 subtype Header =>
25 => as Object
d7611a4a 26 => where { $_->isa('HTTPHeader') };
27
d03bd989 28 coerce Header
29 => from ArrayRef
d7611a4a 30 => via { HTTPHeader->new(array => $_[0]) }
d03bd989 31 => from HashRef
32 => via { HTTPHeader->new(hash => $_[0]) };
33
d7611a4a 34 has 'headers' => (
35 is => 'rw',
36 isa => 'Header',
37 coerce => 1,
38 lazy => 1,
d03bd989 39 default => sub { [ 'content-type', 'text/html' ] }
d7611a4a 40 );
41}
42
43my $r = Request->new;
44isa_ok($r, 'Request');
45
b10dde3a 46is( exception {
d7611a4a 47 $r->headers;
b10dde3a 48}, undef, '... this coerces and passes the type constraint even with lazy' );
d7611a4a 49
a28e50e4 50done_testing;