6 use Test::More tests => 15;
9 use Class::MOP::Instance;
11 my $C = 'Class::MOP::Instance';
14 my $instance = '$self';
15 my $slot_name = '"foo"';
18 is($C->inline_get_slot_value($instance, $slot_name),
20 '... got the right code for get_slot_value');
22 is($C->inline_set_slot_value($instance, $slot_name, $value),
23 '$self->{"foo"} = $value',
24 '... got the right code for set_slot_value');
26 is($C->inline_initialize_slot($instance, $slot_name),
28 '... got the right code for initialize_slot');
30 is($C->inline_is_slot_initialized($instance, $slot_name),
31 'exists $self->{"foo"}',
32 '... got the right code for get_slot_value');
34 is($C->inline_weaken_slot_value($instance, $slot_name),
35 'Scalar::Util::weaken( $self->{"foo"} )',
36 '... got the right code for weaken_slot_value');
38 is($C->inline_strengthen_slot_value($instance, $slot_name),
39 '$self->{"foo"} = $self->{"foo"}',
40 '... got the right code for strengthen_slot_value');
44 my $instance = '$_[0]';
45 my $slot_name = '$attr_name';
48 is($C->inline_get_slot_value($instance, $slot_name),
49 '$_[0]->{$attr_name}',
50 '... got the right code for get_slot_value');
52 is($C->inline_set_slot_value($instance, $slot_name, $value),
53 '$_[0]->{$attr_name} = []',
54 '... got the right code for set_slot_value');
56 is($C->inline_initialize_slot($instance, $slot_name),
58 '... got the right code for initialize_slot');
60 is($C->inline_is_slot_initialized($instance, $slot_name),
61 'exists $_[0]->{$attr_name}',
62 '... got the right code for get_slot_value');
64 is($C->inline_weaken_slot_value($instance, $slot_name),
65 'Scalar::Util::weaken( $_[0]->{$attr_name} )',
66 '... got the right code for weaken_slot_value');
68 is($C->inline_strengthen_slot_value($instance, $slot_name),
69 '$_[0]->{$attr_name} = $_[0]->{$attr_name}',
70 '... got the right code for strengthen_slot_value');
73 my $accessor_string = "sub {\n"
74 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
75 . " if scalar \@_ == 2;\n"
76 . $C->inline_get_slot_value('$_[0]', '$attr_name')
81 $_[0]->{$attr_name} = $_[1] if scalar @_ == 2;
84 '... got the right code string for accessor');
86 my $reader_string = "sub {\n"
87 . $C->inline_get_slot_value('$_[0]', '$attr_name')
94 '... got the right code string for reader');
96 my $writer_string = "sub {\n"
97 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
102 $_[0]->{$attr_name} = $_[1];
104 '... got the right code string for writer');