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)
32 }, undef, '... this works' );
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 Foo->meta->rebless_instance_back($foo)
40 }, undef, '... this works' );
41 is($foo->bar, 'BAR', '... got the expect value');
42 ok(!$foo->can('baz'), '... no baz method though');
45 # with extra params ...
47 my $foo = Foo->new(bar => 'BAR');
50 is($foo->bar, 'BAR', '... got the expect value');
51 ok(!$foo->can('baz'), '... no baz method though');
54 Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ'))
55 }, undef, '... this works' );
57 is($foo->bar, 'BAR', '... got the expect value');
58 ok($foo->can('baz'), '... we have baz method now');
59 is($foo->baz, 'FOO-BAZ', '... got the expect value');
62 Foo->meta->rebless_instance_back($foo)
63 }, undef, '... this works' );
65 is($foo->bar, 'BAR', '... got the expect value');
66 ok(!$foo->can('baz'), '... no baz method though');
67 ok(!exists($foo->{baz}), '... and the baz attribute was deinitialized');
70 # with extra params ...
72 my $foo = Foo->new(bar => 'BAR');
75 is($foo->bar, 'BAR', '... got the expect value');
76 ok(!$foo->can('baz'), '... no baz method though');
79 Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ'))
80 }, undef, '... this works' );
82 is($foo->bar, 'FOO-BAR', '... got the expect value');
83 ok($foo->can('baz'), '... we have baz method now');
84 is($foo->baz, 'FOO-BAZ', '... got the expect value');
87 Foo->meta->rebless_instance_back($foo)
88 }, undef, '... this works' );
90 is($foo->bar, 'FOO-BAR', '... got the expect value');
91 ok(!$foo->can('baz'), '... no baz method though');
92 ok(!exists($foo->{baz}), '... and the baz attribute was deinitialized');