Update Changes, bump version to 0.97_01, make copyright 2006-2010
[gitmo/Class-MOP.git] / t / 047_rebless_with_extra_params.t
CommitLineData
214e4bd7 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
214e4bd7 5use Test::Exception;
6
efd3d14c 7use Class::MOP;
214e4bd7 8
9{
10 package Foo;
11 use metaclass;
12 Foo->meta->add_attribute('bar' => (reader => 'bar'));
86a4d873 13
214e4bd7 14 sub new { (shift)->meta->new_object(@_) }
86a4d873 15
214e4bd7 16 package Bar;
17 use metaclass;
18 use base 'Foo';
86a4d873 19 Bar->meta->add_attribute('baz' => (reader => 'baz', default => 'BAZ'));
214e4bd7 20}
21
22# normal ...
23{
24 my $foo = Foo->new(bar => 'BAR');
25 isa_ok($foo, 'Foo');
26
27 is($foo->bar, 'BAR', '... got the expect value');
28 ok(!$foo->can('baz'), '... no baz method though');
29
30 lives_ok {
31 Bar->meta->rebless_instance($foo)
32 } '... this works';
33
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');
37}
38
39# with extra params ...
40{
41 my $foo = Foo->new(bar => 'BAR');
42 isa_ok($foo, 'Foo');
43
44 is($foo->bar, 'BAR', '... got the expect value');
45 ok(!$foo->can('baz'), '... no baz method though');
46
47 lives_ok {
48 Bar->meta->rebless_instance($foo, (baz => 'FOO-BAZ'))
49 } '... this works';
50
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');
54}
55
56# with extra params ...
57{
58 my $foo = Foo->new(bar => 'BAR');
59 isa_ok($foo, 'Foo');
60
61 is($foo->bar, 'BAR', '... got the expect value');
62 ok(!$foo->can('baz'), '... no baz method though');
63
64 lives_ok {
65 Bar->meta->rebless_instance($foo, (bar => 'FOO-BAR', baz => 'FOO-BAZ'))
66 } '... this works';
67
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');
71}
72
86a4d873 73done_testing;