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