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