4 use Test::More tests => 21;
12 Foo->meta->add_attribute('bar' => (reader => 'bar'));
14 sub new { (shift)->meta->new_object(@_) }
19 Bar->meta->add_attribute('baz' => (reader => 'baz', default => 'BAZ'));
24 my $foo = Foo->new(bar => 'BAR');
27 is($foo->bar, 'BAR', '... got the expect value');
28 ok(!$foo->can('baz'), '... no baz method though');
31 Bar->meta->rebless_instance($foo)
34 is($foo->bar, 'BAR', '... got the expect value');
35 ok($foo->can('baz'), '... we have baz method now');
36 is($foo->baz, 'BAZ', '... got the expect value');
39 # with extra params ...
41 my $foo = Foo->new(bar => 'BAR');
44 is($foo->bar, 'BAR', '... got the expect value');
45 ok(!$foo->can('baz'), '... no baz method though');
48 Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ'))
51 is($foo->bar, 'BAR', '... got the expect value');
52 ok($foo->can('baz'), '... we have baz method now');
53 is($foo->baz, 'FOO-BAZ', '... got the expect value');
56 # with extra params ...
58 my $foo = Foo->new(bar => 'BAR');
61 is($foo->bar, 'BAR', '... got the expect value');
62 ok(!$foo->can('baz'), '... no baz method though');
65 Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ'))
68 is($foo->bar, 'FOO-BAR', '... got the expect value');
69 ok($foo->can('baz'), '... we have baz method now');
70 is($foo->baz, 'FOO-BAZ', '... got the expect value');