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