Commit | Line | Data |
4060c871 |
1 | #!/usr/bin/perl |
1f5ce14a |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
4060c871 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
1f5ce14a |
9 | use Test::More; |
4060c871 |
10 | use Test::Exception; |
11 | |
12 | |
13 | |
14 | { |
15 | package HTTPHeader; |
16 | use Mouse; |
17 | |
18 | has 'array' => (is => 'ro'); |
19 | has 'hash' => (is => 'ro'); |
20 | } |
21 | |
22 | { |
23 | package Request; |
24 | use Mouse; |
25 | use Mouse::Util::TypeConstraints; |
26 | |
27 | subtype Header => |
28 | => as Object |
29 | => where { $_->isa('HTTPHeader') }; |
30 | |
31 | coerce Header |
32 | => from ArrayRef |
33 | => via { HTTPHeader->new(array => $_[0]) } |
34 | => from HashRef |
35 | => via { HTTPHeader->new(hash => $_[0]) }; |
36 | |
37 | has 'headers' => ( |
38 | is => 'rw', |
39 | isa => 'Header', |
40 | coerce => 1, |
41 | lazy => 1, |
42 | default => sub { [ 'content-type', 'text/html' ] } |
43 | ); |
44 | } |
45 | |
46 | my $r = Request->new; |
47 | isa_ok($r, 'Request'); |
48 | |
49 | lives_ok { |
50 | $r->headers; |
51 | } '... this coerces and passes the type constraint even with lazy'; |
52 | |
1f5ce14a |
53 | done_testing; |