File: 201-squirrel.t

package info (click to toggle)
libmouse-perl 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,156 kB
  • sloc: perl: 14,569; ansic: 218; makefile: 8
file content (82 lines) | stat: -rw-r--r-- 1,752 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use Mouse::Spec;

use Scalar::Util 'blessed';

# Don't spew deprecation warnings onto the user's screen
BEGIN {
    $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ /Squirrel is deprecated/ };
}

do {
    package Foo;
    use Squirrel; # load Mouse

    has foo => (
        isa => "Int",
        is  => "rw",
    );

    no Squirrel;
};

# note that 'Foo' is defined before this, to prevent Moose being loaded from
# affecting its definition
BEGIN {
    eval{ require Moose && Moose->VERSION(Mouse::Spec->MooseVersion) };
    plan skip_all => "Moose $Mouse::Spec::MooseVersion required for this test" if $@;
    plan tests => 12;
}

do {
    package Bar;
    use Squirrel; # load Moose

    has foo => (
        isa => "Int",
        is  => "rw",
    );

    no Squirrel;
};

my $foo = Foo->new(foo => 3);
isa_ok($foo, "Foo");
isa_ok($foo, "Mouse::Object");
is($foo->foo, 3, "accessor");

my $bar = Bar->new(foo => 3);
isa_ok($bar, "Bar");
isa_ok($bar, "Moose::Object");
is($bar->foo, 3, "accessor");

ok(!Foo->can('has'), "Mouse::has was unimported");
ok(!Bar->can('has'), "Moose::has was unimported");

eval q{
    package Foo;
    use Squirrel;

    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable;

    package Bar;
    use Squirrel;

    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable;
};
warn $@ if $@;

is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute');
is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports');

is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');