Converted to Build.PL
[gitmo/Class-MOP.git] / t / 102_InsideOutClass_test.t
CommitLineData
52e8a34c 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
e2f8b029 6use Test::More tests => 19;
52e8a34c 7
8BEGIN {
9 use_ok('Class::MOP');
ce87e388 10 use_ok('examples::InsideOutClass');
52e8a34c 11}
12
13{
14 package Foo;
15
16 sub meta { InsideOutClass->initialize($_[0]) }
17
18 Foo->meta->add_attribute(
e2f8b029 19 InsideOutClass::Attribute->new('foo' => (
52e8a34c 20 accessor => 'foo',
21 predicate => 'has_foo',
22 ))
23 );
24
25 Foo->meta->add_attribute(
e2f8b029 26 InsideOutClass::Attribute->new('bar' => (
52e8a34c 27 reader => 'get_bar',
28 writer => 'set_bar',
29 default => 'FOO is BAR'
30 ))
31 );
32
33 sub new {
34 my $class = shift;
35 bless $class->meta->construct_instance() => $class;
36 }
37}
38
39my $foo = Foo->new();
40isa_ok($foo, 'Foo');
41
42can_ok($foo, 'foo');
43can_ok($foo, 'has_foo');
44can_ok($foo, 'get_bar');
45can_ok($foo, 'set_bar');
46
47ok(!$foo->has_foo, '... Foo::foo is not defined yet');
48is($foo->foo(), undef, '... Foo::foo is not defined yet');
49is($foo->get_bar(), 'FOO is BAR', '... Foo::bar has been initialized');
50
51$foo->foo('This is Foo');
52
53ok($foo->has_foo, '... Foo::foo is defined now');
54is($foo->foo(), 'This is Foo', '... Foo::foo == "This is Foo"');
55
56$foo->set_bar(42);
57is($foo->get_bar(), 42, '... Foo::bar == 42');
58
59my $foo2 = Foo->new();
60isa_ok($foo2, 'Foo');
61
62ok(!$foo2->has_foo, '... Foo2::foo is not defined yet');
63is($foo2->foo(), undef, '... Foo2::foo is not defined yet');
64is($foo2->get_bar(), 'FOO is BAR', '... Foo2::bar has been initialized');
65
66$foo2->set_bar('DONT PANIC');
67is($foo2->get_bar(), 'DONT PANIC', '... Foo2::bar == DONT PANIC');
68
69is($foo->get_bar(), 42, '... Foo::bar == 42');