6 use Test::More tests => 21;
14 Foo->meta->add_attribute('bar' => (reader => 'bar'));
16 sub new { (shift)->meta->new_object(@_) }
21 Bar->meta->add_attribute('baz' => (reader => 'baz', default => 'BAZ'));
26 my $foo = Foo->new(bar => 'BAR');
29 is($foo->bar, 'BAR', '... got the expect value');
30 ok(!$foo->can('baz'), '... no baz method though');
33 Bar->meta->rebless_instance($foo)
36 is($foo->bar, 'BAR', '... got the expect value');
37 ok($foo->can('baz'), '... we have baz method now');
38 is($foo->baz, 'BAZ', '... got the expect value');
41 # with extra params ...
43 my $foo = Foo->new(bar => 'BAR');
46 is($foo->bar, 'BAR', '... got the expect value');
47 ok(!$foo->can('baz'), '... no baz method though');
50 Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ'))
53 is($foo->bar, 'BAR', '... got the expect value');
54 ok($foo->can('baz'), '... we have baz method now');
55 is($foo->baz, 'FOO-BAZ', '... got the expect value');
58 # with extra params ...
60 my $foo = Foo->new(bar => 'BAR');
63 is($foo->bar, 'BAR', '... got the expect value');
64 ok(!$foo->can('baz'), '... no baz method though');
67 Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ'))
70 is($foo->bar, 'FOO-BAR', '... got the expect value');
71 ok($foo->can('baz'), '... we have baz method now');
72 is($foo->baz, 'FOO-BAZ', '... got the expect value');