10 eval "use IO::String; use IO::File;";
11 plan skip_all => "IO::String and IO::File are required for this test" if $@;
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 my $st = subtype 'IO::StringOrFile' => as 'IO::String | IO::File';
57 isa => 'IO::StringOrFile',
59 default => sub { IO::String->new() },
64 my $fh = $self->raw_body();
66 return do { local $/; <$fh> };
71 my $email = Email::Mouse->new;
72 isa_ok($email, 'Email::Mouse');
74 isa_ok($email->raw_body, 'IO::String');
76 is($email->as_string, undef, '... got correct empty string');
80 my $email = Email::Mouse->new(raw_body => '... this is my body ...');
81 isa_ok($email, 'Email::Mouse');
83 isa_ok($email->raw_body, 'IO::String');
85 is($email->as_string, '... this is my body ...', '... got correct string');
88 $email->raw_body('... this is the next body ...');
89 } '... this will coerce correctly';
91 isa_ok($email->raw_body, 'IO::String');
93 is($email->as_string, '... this is the next body ...', '... got correct string');
97 my $str = '... this is my body (ref) ...';
99 my $email = Email::Mouse->new(raw_body => \$str);
100 isa_ok($email, 'Email::Mouse');
102 isa_ok($email->raw_body, 'IO::String');
104 is($email->as_string, $str, '... got correct string');
106 my $str2 = '... this is the next body (ref) ...';
109 $email->raw_body(\$str2);
110 } '... this will coerce correctly';
112 isa_ok($email->raw_body, 'IO::String');
114 is($email->as_string, $str2, '... got correct string');
118 my $io_str = IO::String->new('... this is my body (IO::String) ...');
120 my $email = Email::Mouse->new(raw_body => $io_str);
121 isa_ok($email, 'Email::Mouse');
123 isa_ok($email->raw_body, 'IO::String');
124 is($email->raw_body, $io_str, '... and it is the one we expected');
126 is($email->as_string, '... this is my body (IO::String) ...', '... got correct string');
128 my $io_str2 = IO::String->new('... this is the next body (IO::String) ...');
131 $email->raw_body($io_str2);
132 } '... this will coerce correctly';
134 isa_ok($email->raw_body, 'IO::String');
135 is($email->raw_body, $io_str2, '... and it is the one we expected');
137 is($email->as_string, '... this is the next body (IO::String) ...', '... got correct string');
143 open($fh, '<', $0) || die "Could not open $0";
145 my $email = Email::Mouse->new(raw_body => $fh);
146 isa_ok($email, 'Email::Mouse');
148 isa_ok($email->raw_body, 'IO::File');
154 my $fh = IO::File->new($0);
156 my $email = Email::Mouse->new(raw_body => $fh);
157 isa_ok($email, 'Email::Mouse');
159 isa_ok($email->raw_body, 'IO::File');
160 is($email->raw_body, $fh, '... and it is the one we expected');