Moose now warns when you try to load it from the main package. Added a
[gitmo/Moose.git] / t / 020_attributes / 014_misc_attribute_coerce_lazy.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 2;
7 use Test::Exception;
8
9
10
11 {
12     package HTTPHeader;
13     use Moose;
14     
15     has 'array' => (is => 'ro');
16     has 'hash'  => (is => 'ro');    
17 }
18
19 {
20     package Request;
21     use Moose;
22     use Moose::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
43 my $r = Request->new;
44 isa_ok($r, 'Request');
45
46 lives_ok {
47     $r->headers;
48 } '... this coerces and passes the type constraint even with lazy';
49
50
51