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;
13 'IO::String' => '0.01', # skip all if not installed
20 use Mouse::Util::TypeConstraints;
24 our $VERSION = '0.01';
26 # create subtype for IO::String
30 => where { $_->isa('IO::String') };
34 => via { IO::String->new($_) },
36 => via { IO::String->new($_) };
38 # create subtype for IO::File
42 => where { $_->isa('IO::File') };
46 => via { bless $_, 'IO::File' };
50 subtype 'IO::StringOrFile' => as 'IO::String | IO::File';
56 isa => 'IO::StringOrFile',
58 default => sub { IO::String->new() },
63 my $fh = $self->raw_body();
64 return do { local $/; <$fh> };
69 my $email = Email::Mouse->new;
70 isa_ok($email, 'Email::Mouse');
72 isa_ok($email->raw_body, 'IO::String');
74 is($email->as_string, undef, '... got correct empty string');
78 my $email = Email::Mouse->new(raw_body => '... this is my body ...');
79 isa_ok($email, 'Email::Mouse');
81 isa_ok($email->raw_body, 'IO::String');
83 is($email->as_string, '... this is my body ...', '... got correct string');
86 $email->raw_body('... this is the next body ...');
87 } '... this will coerce correctly';
89 isa_ok($email->raw_body, 'IO::String');
91 is($email->as_string, '... this is the next body ...', '... got correct string');
95 my $str = '... this is my body (ref) ...';
97 my $email = Email::Mouse->new(raw_body => \$str);
98 isa_ok($email, 'Email::Mouse');
100 isa_ok($email->raw_body, 'IO::String');
102 is($email->as_string, $str, '... got correct string');
104 my $str2 = '... this is the next body (ref) ...';
107 $email->raw_body(\$str2);
108 } '... this will coerce correctly';
110 isa_ok($email->raw_body, 'IO::String');
112 is($email->as_string, $str2, '... got correct string');
116 my $io_str = IO::String->new('... this is my body (IO::String) ...');
118 my $email = Email::Mouse->new(raw_body => $io_str);
119 isa_ok($email, 'Email::Mouse');
121 isa_ok($email->raw_body, 'IO::String');
122 is($email->raw_body, $io_str, '... and it is the one we expected');
124 is($email->as_string, '... this is my body (IO::String) ...', '... got correct string');
126 my $io_str2 = IO::String->new('... this is the next body (IO::String) ...');
129 $email->raw_body($io_str2);
130 } '... this will coerce correctly';
132 isa_ok($email->raw_body, 'IO::String');
133 is($email->raw_body, $io_str2, '... and it is the one we expected');
135 is($email->as_string, '... this is the next body (IO::String) ...', '... got correct string');
141 open($fh, '<', $0) || die "Could not open $0";
143 my $email = Email::Mouse->new(raw_body => $fh);
144 isa_ok($email, 'Email::Mouse');
146 isa_ok($email->raw_body, 'IO::File');
152 my $fh = IO::File->new($0);
154 my $email = Email::Mouse->new(raw_body => $fh);
155 isa_ok($email, 'Email::Mouse');
157 isa_ok($email->raw_body, 'IO::File');
158 is($email->raw_body, $fh, '... and it is the one we expected');
165 use Mouse::Util::TypeConstraints;
167 subtype 'Coerced' => as 'ArrayRef';
174 isa => 'Coerced | Coerced',
181 lives_ok { $foo = Foo->new( carray => 1 ) }
182 'Can pass non-ref value for carray';
185 'carray was coerced to an array ref'
188 throws_ok { Foo->new( carray => {} ) }
189 qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/,
190 'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef';