X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F040_type_constraints%2F009_union_types_and_coercions.t;fp=t%2F040_type_constraints%2F009_union_types_and_coercions.t;h=ca8fcab4035aed4ad99c53292f2da8c4447a42e2;hb=9864f0e4ba233c5f30ad6dc7c484ced43d883d27;hp=91f7cc888efc1cc51a8b83721bb3244f06210661;hpb=8845df4dd6432e3164d078ade741409061adae9f;p=gitmo%2FMouse.git diff --git a/t/040_type_constraints/009_union_types_and_coercions.t b/t/040_type_constraints/009_union_types_and_coercions.t index 91f7cc8..ca8fcab 100644 --- a/t/040_type_constraints/009_union_types_and_coercions.t +++ b/t/040_type_constraints/009_union_types_and_coercions.t @@ -1,7 +1,4 @@ #!/usr/bin/perl -# This is automatically generated by author/import-moose-test.pl. -# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! -use t::lib::MooseCompat; use strict; use warnings; @@ -9,10 +6,13 @@ use warnings; use Test::More; use Test::Exception; -use Test::Requires { - 'IO::String' => '0.01', # skip all if not installed - 'IO::File' => '0.01', -}; +BEGIN { + eval "use IO::String; use IO::File;"; + plan skip_all => "IO::String and IO::File are required for this test" if $@; + plan tests => 28; +} + + { package Email::Mouse; @@ -47,7 +47,8 @@ use Test::Requires { # create the alias - subtype 'IO::StringOrFile' => as 'IO::String | IO::File'; + my $st = subtype 'IO::StringOrFile' => as 'IO::String | IO::File'; + #::diag $st->dump; # attributes @@ -61,6 +62,7 @@ use Test::Requires { sub as_string { my ($self) = @_; my $fh = $self->raw_body(); + return do { local $/; <$fh> }; } } @@ -158,36 +160,5 @@ use Test::Requires { is($email->raw_body, $fh, '... and it is the one we expected'); } -{ - package Foo; - - use Mouse; - use Mouse::Util::TypeConstraints; - - subtype 'Coerced' => as 'ArrayRef'; - coerce 'Coerced' - => from 'Value' - => via { [ $_ ] }; - - has carray => ( - is => 'ro', - isa => 'Coerced | Coerced', - coerce => 1, - ); -} - -{ - my $foo; - lives_ok { $foo = Foo->new( carray => 1 ) } - 'Can pass non-ref value for carray'; - is_deeply( - $foo->carray, [1], - 'carray was coerced to an array ref' - ); - throws_ok { Foo->new( carray => {} ) } - qr/\QValidation failed for 'Coerced|Coerced' with value \E(?!undef)/, - 'Cannot pass a hash ref for carray attribute, and hash ref is not coerced to an undef'; -} -done_testing;