Fix magic handling in type constraints (reported by sunnavy)
[gitmo/Mouse.git] / t / 001_mouse / 066-magic.t
1 #!perl
2 use strict;
3 use warnings;
4 use Test::More tests => 3;
5
6 use Tie::Scalar;
7
8 {
9     package MyClass;
10     use Mouse;
11
12     has foo => (
13         is  => 'rw',
14         isa => 'Int',
15     );
16     has bar => (
17         is  => 'rw',
18         isa => 'Maybe[Int]',
19     );
20 }
21
22 sub ts_init {
23     tie $_[0], 'Tie::StdScalar', $_[1];
24 }
25
26 ts_init(my $x, 10);
27
28 my $o = MyClass->new();
29 is(eval{ $o->foo($x) }, 10)
30     or diag("Error: $@");
31
32 ts_init($x, 'foo');
33
34 eval{
35     $o->bar($x);
36 };
37 isnt $@, '';
38
39 ts_init $x, 42;
40 is(eval{ $o->bar($x) }, 42)
41     or diag("Error: $@");
42