Make Mouse::Util::load_class return the argument class name, which can remove several...
[gitmo/Mouse.git] / t / 810_with_moose / 201-squirrel.t
CommitLineData
7a1781ae 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8use Mouse::Spec;
9
10use Scalar::Util 'blessed';
11
12# Don't spew deprecation warnings onto the user's screen
13BEGIN {
14 $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ /Squirrel is deprecated/ };
15}
16
17do {
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
31BEGIN {
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
37do {
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
49my $foo = Foo->new(foo => 3);
50isa_ok($foo, "Foo");
51isa_ok($foo, "Mouse::Object");
52is($foo->foo, 3, "accessor");
53
54my $bar = Bar->new(foo => 3);
55isa_ok($bar, "Bar");
56isa_ok($bar, "Moose::Object");
57is($bar->foo, 3, "accessor");
58
59ok(!Foo->can('has'), "Mouse::has was unimported");
60ok(!Bar->can('has'), "Moose::has was unimported");
61
62eval 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};
75warn $@ if $@;
76
77is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute');
78is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports');
79
80is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
81is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');
82