Fix prototype on message {...}
[gitmo/Mouse.git] / t / 100-meta-class.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
986ff64a 4use Test::More tests => 14;
c3398f5b 5
6do {
7 package Class;
8 use Mouse;
9
10 has pawn => (
11 is => 'rw',
12 predicate => 'has_pawn',
13 );
14
15 no Mouse;
16};
17
18my $meta = Class->meta;
306290e8 19isa_ok($meta, 'Mouse::Meta::Class');
c3398f5b 20
21is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mouse::Object");
22
23my $meta2 = Class->meta;
24is($meta, $meta2, "same metaclass instance");
25
f89acace 26can_ok($meta, 'name', 'get_attribute_map');
c3398f5b 27
986ff64a 28ok($meta->has_attribute('pawn'));
c3398f5b 29my $attr = $meta->get_attribute('pawn');
306290e8 30isa_ok($attr, 'Mouse::Meta::Attribute');
c3398f5b 31is($attr->name, 'pawn', 'got the correct attribute');
32
33my $map = $meta->get_attribute_map;
34is_deeply($map, { pawn => $attr }, "attribute map");
35
986ff64a 36ok(!$meta->has_attribute('nonexistent_attribute'));
37
c3398f5b 38eval "
39 package Class;
40 use Mouse;
41 no Mouse;
42";
43
44my $meta3 = Class->meta;
45is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again");
46
47is($meta->name, 'Class', "name for the metaclass");
48
49do {
50 package Child;
51 use Mouse;
52 extends 'Class';
53};
54
55my $child_meta = Child->meta;
306290e8 56isa_ok($child_meta, 'Mouse::Meta::Class');
c3398f5b 57
58isnt($meta, $child_meta, "different metaclass instances for the two classes");
59
60is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses");