Resolve a todo
[gitmo/Mouse.git] / t / 020_attributes / 014_misc_attribute_coerce_lazy.t
CommitLineData
4060c871 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 2;
7use Test::Exception;
8
9
10
11{
12 package HTTPHeader;
13 use Mouse;
14
15 has 'array' => (is => 'ro');
16 has 'hash' => (is => 'ro');
17}
18
19{
20 package Request;
21 use Mouse;
22 use Mouse::Util::TypeConstraints;
23
24 subtype Header =>
25 => as Object
26 => where { $_->isa('HTTPHeader') };
27
28 coerce Header
29 => from ArrayRef
30 => via { HTTPHeader->new(array => $_[0]) }
31 => from HashRef
32 => via { HTTPHeader->new(hash => $_[0]) };
33
34 has 'headers' => (
35 is => 'rw',
36 isa => 'Header',
37 coerce => 1,
38 lazy => 1,
39 default => sub { [ 'content-type', 'text/html' ] }
40 );
41}
42
43my $r = Request->new;
44isa_ok($r, 'Request');
45
46lives_ok {
47 $r->headers;
48} '... this coerces and passes the type constraint even with lazy';
49
50
51