Commit | Line | Data |
2bab2be6 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
c174112e |
6 | use Test::More tests => 22; |
2bab2be6 |
7 | use Test::Exception; |
8 | |
2bab2be6 |
9 | BEGIN { |
10 | use_ok('Class::MOP::Instance'); |
11 | } |
12 | |
de943e6a |
13 | can_ok( "Class::MOP::Instance", $_ ) for qw/ |
49c93440 |
14 | new |
15 | |
de943e6a |
16 | create_instance |
17 | bless_instance_structure |
18 | |
49c93440 |
19 | get_all_slots |
de943e6a |
20 | |
21 | get_slot_value |
22 | set_slot_value |
c174112e |
23 | initialize_slot |
24 | initialize_all_slots |
25 | is_slot_initialized |
de943e6a |
26 | /; |
27 | |
28 | { |
29 | package Foo; |
30 | use metaclass; |
49c93440 |
31 | |
32 | Foo->meta->add_attribute('moosen'); |
de943e6a |
33 | |
34 | package Bar; |
35 | use metaclass; |
36 | use base qw/Foo/; |
de943e6a |
37 | |
49c93440 |
38 | Bar->meta->add_attribute('elken'); |
39 | } |
de943e6a |
40 | |
49c93440 |
41 | my $mi_foo = Foo->meta->get_meta_instance; |
42 | isa_ok($mi_foo, "Class::MOP::Instance"); |
de943e6a |
43 | |
49c93440 |
44 | is_deeply( |
45 | [ $mi_foo->get_all_slots ], |
46 | [ "moosen" ], |
47 | '... get all slots for Foo'); |
de943e6a |
48 | |
49 | my $mi_bar = Bar->meta->get_meta_instance; |
49c93440 |
50 | isa_ok($mi_bar, "Class::MOP::Instance"); |
de943e6a |
51 | |
49c93440 |
52 | isnt($mi_foo, $mi_bar, '... they are not the same instance'); |
de943e6a |
53 | |
49c93440 |
54 | is_deeply( |
55 | [ sort $mi_bar->get_all_slots ], |
56 | [ "elken", "moosen" ], |
57 | '... get all slots for Bar'); |
de943e6a |
58 | |
49c93440 |
59 | my $i_foo = $mi_foo->create_instance; |
60 | isa_ok($i_foo, "Foo"); |
de943e6a |
61 | |
49c93440 |
62 | { |
63 | my $i_foo_2 = $mi_foo->create_instance; |
64 | isa_ok($i_foo_2, "Foo"); |
65 | isnt($i_foo_2, $i_foo, '... not the same instance'); |
66 | is_deeply($i_foo, $i_foo_2, '... but the same structure'); |
67 | } |
de943e6a |
68 | |
49c93440 |
69 | ok(!defined($mi_foo->get_slot_value( $i_foo, "moosen" )), "... no value for slot"); |
de943e6a |
70 | |
de943e6a |
71 | $mi_foo->set_slot_value( $i_foo, "moosen", "the value" ); |
72 | |
49c93440 |
73 | is($mi_foo->get_slot_value( $i_foo, "moosen" ), "the value", "... get slot value"); |
74 | |
75 | ok(!$i_foo->can('moosen'), '... Foo cant moosen'); |