6 use Test::More tests => 22;
16 Foo->meta->add_attribute('bar' => (reader => 'bar'));
18 sub new { (shift)->meta->new_object(@_) }
23 Bar->meta->add_attribute('baz' => (reader => 'baz', default => 'BAZ'));
28 my $foo = Foo->new(bar => 'BAR');
31 is($foo->bar, 'BAR', '... got the expect value');
32 ok(!$foo->can('baz'), '... no baz method though');
35 Bar->meta->rebless_instance($foo)
38 is($foo->bar, 'BAR', '... got the expect value');
39 ok($foo->can('baz'), '... we have baz method now');
40 is($foo->baz, 'BAZ', '... got the expect value');
43 # with extra params ...
45 my $foo = Foo->new(bar => 'BAR');
48 is($foo->bar, 'BAR', '... got the expect value');
49 ok(!$foo->can('baz'), '... no baz method though');
52 Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ'))
55 is($foo->bar, 'BAR', '... got the expect value');
56 ok($foo->can('baz'), '... we have baz method now');
57 is($foo->baz, 'FOO-BAZ', '... got the expect value');
60 # with extra params ...
62 my $foo = Foo->new(bar => 'BAR');
65 is($foo->bar, 'BAR', '... got the expect value');
66 ok(!$foo->can('baz'), '... no baz method though');
69 Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ'))
72 is($foo->bar, 'FOO-BAR', '... got the expect value');
73 ok($foo->can('baz'), '... we have baz method now');
74 is($foo->baz, 'FOO-BAZ', '... got the expect value');