Commit | Line | Data |
692e1bcd |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
6c169c50 |
7 | use Scalar::Util 'blessed'; |
692e1bcd |
8 | |
b03fda9f |
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 | |
eb061d5b |
14 | do { |
692e1bcd |
15 | package Foo; |
16 | use Squirrel; |
17 | |
18 | has foo => ( |
19 | isa => "Int", |
20 | is => "rw", |
21 | ); |
eb061d5b |
22 | |
23 | no Squirrel; |
24 | }; |
692e1bcd |
25 | |
26 | # note that 'Foo' is defined before this, to prevent Moose being loaded from |
27 | # affecting its definition |
28 | |
29 | BEGIN { |
9cc87fff |
30 | plan skip_all => "Moose 0.68 required for this test" unless eval { require Moose && Moose->VERSION('0.68') }; |
eb061d5b |
31 | plan tests => 12; |
692e1bcd |
32 | } |
33 | |
eb061d5b |
34 | do { |
692e1bcd |
35 | package Bar; |
36 | use Squirrel; |
37 | |
38 | has foo => ( |
39 | isa => "Int", |
40 | is => "rw", |
41 | ); |
692e1bcd |
42 | |
eb061d5b |
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"); |
692e1bcd |
55 | |
eb061d5b |
56 | ok(!Foo->can('has'), "Mouse::has was unimported"); |
57 | ok(!Bar->can('has'), "Moose::has was unimported"); |
692e1bcd |
58 | |
eb061d5b |
59 | eval " |
60 | package Foo; |
61 | use Squirrel; |
62 | |
63 | has bar => (is => 'rw'); |
60e2164a |
64 | __PACKAGE__->meta->make_immutable; |
692e1bcd |
65 | |
eb061d5b |
66 | package Bar; |
67 | use Squirrel; |
692e1bcd |
68 | |
eb061d5b |
69 | has bar => (is => 'rw'); |
60e2164a |
70 | __PACKAGE__->meta->make_immutable; |
eb061d5b |
71 | "; |
60e2164a |
72 | warn $@ if $@; |
692e1bcd |
73 | |
eb061d5b |
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'); |
692e1bcd |
76 | |
eb061d5b |
77 | is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute'); |
78 | is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute'); |
692e1bcd |
79 | |