Commit | Line | Data |
3a79f0e9 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7ff56534 |
6 | use Test::More tests => 21; |
3a79f0e9 |
7 | use Test::Exception; |
8 | |
7ff56534 |
9 | |
3a79f0e9 |
10 | |
11 | { |
12 | package Foo; |
13 | use Moose; |
14 | has 'bar' => (is => 'ro'); |
d03bd989 |
15 | |
3a79f0e9 |
16 | package Bar; |
17 | use Moose::Role; |
d03bd989 |
18 | |
19 | has 'baz' => (is => 'ro', default => 'BAZ'); |
3a79f0e9 |
20 | } |
21 | |
22 | # normal ... |
23 | { |
24 | my $foo = Foo->new(bar => 'BAR'); |
25 | isa_ok($foo, 'Foo'); |
26 | |
1808c2da |
27 | is($foo->bar, 'BAR', 'got the expect value'); |
28 | ok(!$foo->can('baz'), 'no baz method though'); |
3a79f0e9 |
29 | |
30 | lives_ok { |
31 | Bar->meta->apply($foo) |
1808c2da |
32 | } 'this works'; |
3a79f0e9 |
33 | |
1808c2da |
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'); |
3a79f0e9 |
37 | } |
38 | |
39 | # with extra params ... |
40 | { |
41 | my $foo = Foo->new(bar => 'BAR'); |
42 | isa_ok($foo, 'Foo'); |
43 | |
1808c2da |
44 | is($foo->bar, 'BAR', 'got the expect value'); |
45 | ok(!$foo->can('baz'), 'no baz method though'); |
3a79f0e9 |
46 | |
47 | lives_ok { |
48 | Bar->meta->apply($foo, (rebless_params => { baz => 'FOO-BAZ' })) |
1808c2da |
49 | } 'this works'; |
3a79f0e9 |
50 | |
1808c2da |
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'); |
3a79f0e9 |
54 | } |
55 | |
56 | # with extra params ... |
57 | { |
58 | my $foo = Foo->new(bar => 'BAR'); |
59 | isa_ok($foo, 'Foo'); |
60 | |
1808c2da |
61 | is($foo->bar, 'BAR', 'got the expect value'); |
62 | ok(!$foo->can('baz'), 'no baz method though'); |
3a79f0e9 |
63 | |
64 | lives_ok { |
65 | Bar->meta->apply($foo, (rebless_params => { bar => 'FOO-BAR', baz => 'FOO-BAZ' })) |
1808c2da |
66 | } 'this works'; |
3a79f0e9 |
67 | |
1808c2da |
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'); |
3a79f0e9 |
71 | } |
72 | |
73 | |