Refactor code to get a metaclass object's real class name into a method.
[gitmo/Class-MOP.git] / t / 103_Perl6Attribute_test.t
CommitLineData
e2f8b029 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
9ec169fe 5use File::Spec;
e2f8b029 6
86a4d873 7use Class::MOP;
8
9BEGIN {
10dd437b 10 require_ok(File::Spec->catfile('examples', 'Perl6Attribute.pod'));
e2f8b029 11}
12
13{
14 package Foo;
86a4d873 15
c9e77dbb 16 use metaclass;
86a4d873 17
e2f8b029 18 Foo->meta->add_attribute(Perl6Attribute->new('$.foo'));
86a4d873 19 Foo->meta->add_attribute(Perl6Attribute->new('@.bar'));
20 Foo->meta->add_attribute(Perl6Attribute->new('%.baz'));
21
e2f8b029 22 sub new {
23 my $class = shift;
5659d76e 24 $class->meta->new_object(@_);
86a4d873 25 }
e2f8b029 26}
27
28my $foo = Foo->new();
29isa_ok($foo, 'Foo');
30
31can_ok($foo, 'foo');
32can_ok($foo, 'bar');
33can_ok($foo, 'baz');
34
35is($foo->foo, undef, '... Foo.foo == undef');
36
37$foo->foo(42);
38is($foo->foo, 42, '... Foo.foo == 42');
39
40is_deeply($foo->bar, [], '... Foo.bar == []');
41is_deeply($foo->baz, {}, '... Foo.baz == {}');
86a4d873 42
43done_testing;