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 | |
eb061d5b |
9 | do { |
692e1bcd |
10 | package Foo; |
11 | use Squirrel; |
12 | |
13 | has foo => ( |
14 | isa => "Int", |
15 | is => "rw", |
16 | ); |
eb061d5b |
17 | |
18 | no Squirrel; |
19 | }; |
692e1bcd |
20 | |
21 | # note that 'Foo' is defined before this, to prevent Moose being loaded from |
22 | # affecting its definition |
23 | |
24 | BEGIN { |
25 | plan skip_all => "Moose required for this test" unless eval { require Moose }; |
eb061d5b |
26 | plan tests => 12; |
692e1bcd |
27 | } |
28 | |
eb061d5b |
29 | do { |
692e1bcd |
30 | package Bar; |
31 | use Squirrel; |
32 | |
33 | has foo => ( |
34 | isa => "Int", |
35 | is => "rw", |
36 | ); |
692e1bcd |
37 | |
eb061d5b |
38 | no Squirrel; |
39 | }; |
40 | |
41 | my $foo = Foo->new(foo => 3); |
42 | isa_ok($foo, "Foo"); |
43 | isa_ok($foo, "Mouse::Object"); |
44 | is($foo->foo, 3, "accessor"); |
45 | |
46 | my $bar = Bar->new(foo => 3); |
47 | isa_ok($bar, "Bar"); |
48 | isa_ok($bar, "Moose::Object"); |
49 | is($bar->foo, 3, "accessor"); |
692e1bcd |
50 | |
eb061d5b |
51 | ok(!Foo->can('has'), "Mouse::has was unimported"); |
52 | ok(!Bar->can('has'), "Moose::has was unimported"); |
692e1bcd |
53 | |
eb061d5b |
54 | eval " |
55 | package Foo; |
56 | use Squirrel; |
57 | |
58 | has bar => (is => 'rw'); |
60e2164a |
59 | __PACKAGE__->meta->make_immutable; |
692e1bcd |
60 | |
eb061d5b |
61 | package Bar; |
62 | use Squirrel; |
692e1bcd |
63 | |
eb061d5b |
64 | has bar => (is => 'rw'); |
60e2164a |
65 | __PACKAGE__->meta->make_immutable; |
eb061d5b |
66 | "; |
60e2164a |
67 | warn $@ if $@; |
692e1bcd |
68 | |
eb061d5b |
69 | is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute'); |
70 | is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports'); |
692e1bcd |
71 | |
eb061d5b |
72 | is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute'); |
73 | is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute'); |
692e1bcd |
74 | |