6 use Test::More tests => 16;
10 use_ok('Class::MOP::Instance');
13 my $C = 'Class::MOP::Instance';
16 my $instance = '$self';
17 my $slot_name = '"foo"';
20 is($C->inline_get_slot_value($instance, $slot_name),
22 '... got the right code for get_slot_value');
24 is($C->inline_set_slot_value($instance, $slot_name, $value),
25 '$self->{"foo"} = $value',
26 '... got the right code for set_slot_value');
28 is($C->inline_initialize_slot($instance, $slot_name),
29 '$self->{"foo"} = undef',
30 '... got the right code for initialize_slot');
32 is($C->inline_is_slot_initialized($instance, $slot_name),
33 'exists $self->{"foo"}',
34 '... got the right code for get_slot_value');
36 is($C->inline_weaken_slot_value($instance, $slot_name),
37 'Scalar::Util::weaken( $self->{"foo"} )',
38 '... got the right code for weaken_slot_value');
40 is($C->inline_strengthen_slot_value($instance, $slot_name),
41 '$self->{"foo"} = $self->{"foo"}',
42 '... got the right code for strengthen_slot_value');
46 my $instance = '$_[0]';
47 my $slot_name = '$attr_name';
50 is($C->inline_get_slot_value($instance, $slot_name),
51 '$_[0]->{$attr_name}',
52 '... got the right code for get_slot_value');
54 is($C->inline_set_slot_value($instance, $slot_name, $value),
55 '$_[0]->{$attr_name} = []',
56 '... got the right code for set_slot_value');
58 is($C->inline_initialize_slot($instance, $slot_name),
59 '$_[0]->{$attr_name} = undef',
60 '... got the right code for initialize_slot');
62 is($C->inline_is_slot_initialized($instance, $slot_name),
63 'exists $_[0]->{$attr_name}',
64 '... got the right code for get_slot_value');
66 is($C->inline_weaken_slot_value($instance, $slot_name),
67 'Scalar::Util::weaken( $_[0]->{$attr_name} )',
68 '... got the right code for weaken_slot_value');
70 is($C->inline_strengthen_slot_value($instance, $slot_name),
71 '$_[0]->{$attr_name} = $_[0]->{$attr_name}',
72 '... got the right code for strengthen_slot_value');
75 my $accessor_string = "sub {\n"
76 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
77 . " if scalar \@_ == 2;\n"
78 . $C->inline_get_slot_value('$_[0]', '$attr_name')
83 $_[0]->{$attr_name} = $_[1] if scalar @_ == 2;
86 '... got the right code string for accessor');
88 my $reader_string = "sub {\n"
89 . $C->inline_get_slot_value('$_[0]', '$attr_name')
96 '... got the right code string for reader');
98 my $writer_string = "sub {\n"
99 . $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
104 $_[0]->{$attr_name} = $_[1];
106 '... got the right code string for writer');