Regenerate test files
[gitmo/Mouse.git] / t / 020_attributes / 014_misc_attribute_coerce_lazy.t
CommitLineData
4060c871 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
fde8e43f 9use Test::More;
4060c871 10use 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
46my $r = Request->new;
47isa_ok($r, 'Request');
48
49lives_ok {
50 $r->headers;
51} '... this coerces and passes the type constraint even with lazy';
52
fde8e43f 53done_testing;