daeed221d206528bb7cd0b19052e52f9aa89923a
[gitmo/Mouse.git] / t / 201-squirrel.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Scalar::Util 'blessed';
8
9 # Don't spew deprecation warnings onto the user's screen
10 BEGIN {
11     $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ /Squirrel is deprecated/ };
12 }
13
14 do {
15     package Foo;
16     use Squirrel;
17
18     has foo => (
19         isa => "Int",
20         is  => "rw",
21     );
22
23     no Squirrel;
24 };
25
26 # note that 'Foo' is defined before this, to prevent Moose being loaded from
27 # affecting its definition
28
29 BEGIN {
30     plan skip_all => "Moose 0.68 required for this test" unless eval { require Moose && Moose->VERSION('0.68') };
31     plan tests => 12;
32 }
33
34 do {
35     package Bar;
36     use Squirrel;
37
38     has foo => (
39         isa => "Int",
40         is  => "rw",
41     );
42
43     no Squirrel;
44 };
45
46 my $foo = Foo->new(foo => 3);
47 isa_ok($foo, "Foo");
48 isa_ok($foo, "Mouse::Object");
49 is($foo->foo, 3, "accessor");
50
51 my $bar = Bar->new(foo => 3);
52 isa_ok($bar, "Bar");
53 isa_ok($bar, "Moose::Object");
54 is($bar->foo, 3, "accessor");
55
56 ok(!Foo->can('has'), "Mouse::has was unimported");
57 ok(!Bar->can('has'), "Moose::has was unimported");
58
59 eval "
60     package Foo;
61     use Squirrel;
62
63     has bar => (is => 'rw');
64     __PACKAGE__->meta->make_immutable;
65
66     package Bar;
67     use Squirrel;
68
69     has bar => (is => 'rw');
70     __PACKAGE__->meta->make_immutable;
71 ";
72 warn $@ if $@;
73
74 is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute');
75 is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports');
76
77 is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
78 is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');
79