6 use Test::More tests => 65;
11 require_ok(File::Spec->catdir('examples', 'InsideOutClass.pod'));
20 use metaclass 'Class::MOP::Class' => (
21 ':instance_metaclass' => 'InsideOutClass::Instance'
24 Foo->meta->add_attribute('foo' => (
26 predicate => 'has_foo',
29 Foo->meta->add_attribute('bar' => (
32 default => 'FOO is BAR'
37 $class->meta->new_object(@_);
47 Bar->meta->add_attribute('baz' => (
49 predicate => 'has_baz',
56 use metaclass 'Class::MOP::Class' => (
57 ':instance_metaclass' => 'InsideOutClass::Instance'
60 Baz->meta->add_attribute('bling' => (
62 default => 'Baz::bling'
70 use base 'Bar', 'Baz';
77 can_ok($foo, 'has_foo');
78 can_ok($foo, 'get_bar');
79 can_ok($foo, 'set_bar');
81 ok(!$foo->has_foo, '... Foo::foo is not defined yet');
82 is($foo->foo(), undef, '... Foo::foo is not defined yet');
83 is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
85 $foo->foo('This is Foo');
87 ok($foo->has_foo, '... Foo::foo is defined now');
88 is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
91 is($foo->get_bar(), 42, '... Foo::bar == 42');
93 my $foo2 = Foo->new();
96 ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
97 is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
98 is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
100 $foo2->set_bar('DONT PANIC');
101 is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
103 is($foo->get_bar(), 42, '... Foo::bar == 42');
107 my $bar = Bar->new();
112 can_ok($bar, 'has_foo');
113 can_ok($bar, 'get_bar');
114 can_ok($bar, 'set_bar');
116 can_ok($bar, 'has_baz');
118 ok(!$bar->has_foo, '... Bar::foo is not defined yet');
119 is($bar->foo(), undef, '... Bar::foo is not defined yet');
120 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
121 ok(!$bar->has_baz, '... Bar::baz is not defined yet');
122 is($bar->baz(), undef, '... Bar::baz is not defined yet');
124 $bar->foo('This is Bar::foo');
126 ok($bar->has_foo, '... Bar::foo is defined now');
127 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
128 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
130 $bar->baz('This is Bar::baz');
132 ok($bar->has_baz, '... Bar::baz is defined now');
133 is($bar->baz(), 'This is Bar::baz', '... Bar::foo == "This is Bar"');
134 is($bar->foo(), 'This is Bar::foo', '... Bar::foo == "This is Bar"');
135 is($bar->get_bar(), 'FOO is BAR', '... Bar::bar has been initialized');
139 my $baz = Bar::Baz->new();
140 isa_ok($baz, 'Bar::Baz');
146 can_ok($baz, 'has_foo');
147 can_ok($baz, 'get_bar');
148 can_ok($baz, 'set_bar');
150 can_ok($baz, 'has_baz');
151 can_ok($baz, 'bling');
153 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
154 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
156 ok(!$baz->has_foo, '... Bar::Baz::foo is not defined yet');
157 is($baz->foo(), undef, '... Bar::Baz::foo is not defined yet');
158 ok(!$baz->has_baz, '... Bar::Baz::baz is not defined yet');
159 is($baz->baz(), undef, '... Bar::Baz::baz is not defined yet');
161 $baz->foo('This is Bar::Baz::foo');
163 ok($baz->has_foo, '... Bar::Baz::foo is defined now');
164 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
165 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
166 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');
168 $baz->baz('This is Bar::Baz::baz');
170 ok($baz->has_baz, '... Bar::Baz::baz is defined now');
171 is($baz->baz(), 'This is Bar::Baz::baz', '... Bar::Baz::foo == "This is Bar"');
172 is($baz->foo(), 'This is Bar::Baz::foo', '... Bar::Baz::foo == "This is Bar"');
173 is($baz->get_bar(), 'FOO is BAR', '... Bar::Baz::bar has been initialized');
174 is($baz->bling(), 'Baz::bling', '... Bar::Baz::bling has been initialized');