Improve is_class_loaded checking
[gitmo/Class-MOP.git] / t / 061_instance_inline.t
CommitLineData
ee7c0467 1use strict;
2use warnings;
3
efd3d14c 4use Test::More tests => 15;
ee7c0467 5use Test::Exception;
6
efd3d14c 7use Class::MOP::Instance;
ee7c0467 8
9my $C = 'Class::MOP::Instance';
10
11{
12 my $instance = '$self';
13 my $slot_name = '"foo"';
14 my $value = '$value';
15
8d2d4c67 16 is($C->inline_get_slot_value($instance, $slot_name),
230472a7 17 '$self->{"foo"}',
ee7c0467 18 '... got the right code for get_slot_value');
8d2d4c67 19
20 is($C->inline_set_slot_value($instance, $slot_name, $value),
ee7c0467 21 '$self->{"foo"} = $value',
8d2d4c67 22 '... got the right code for set_slot_value');
ee7c0467 23
8d2d4c67 24 is($C->inline_initialize_slot($instance, $slot_name),
a007159d 25 '',
ee7c0467 26 '... got the right code for initialize_slot');
8d2d4c67 27
28 is($C->inline_is_slot_initialized($instance, $slot_name),
230472a7 29 'exists $self->{"foo"}',
8d2d4c67 30 '... got the right code for get_slot_value');
31
32 is($C->inline_weaken_slot_value($instance, $slot_name),
ee7c0467 33 'Scalar::Util::weaken( $self->{"foo"} )',
8d2d4c67 34 '... got the right code for weaken_slot_value');
35
36 is($C->inline_strengthen_slot_value($instance, $slot_name),
ee7c0467 37 '$self->{"foo"} = $self->{"foo"}',
8d2d4c67 38 '... got the right code for strengthen_slot_value');
39}
40
ee7c0467 41{
42 my $instance = '$_[0]';
43 my $slot_name = '$attr_name';
44 my $value = '[]';
45
8d2d4c67 46 is($C->inline_get_slot_value($instance, $slot_name),
230472a7 47 '$_[0]->{$attr_name}',
ee7c0467 48 '... got the right code for get_slot_value');
8d2d4c67 49
50 is($C->inline_set_slot_value($instance, $slot_name, $value),
ee7c0467 51 '$_[0]->{$attr_name} = []',
8d2d4c67 52 '... got the right code for set_slot_value');
53
54 is($C->inline_initialize_slot($instance, $slot_name),
a007159d 55 '',
8d2d4c67 56 '... got the right code for initialize_slot');
57
58 is($C->inline_is_slot_initialized($instance, $slot_name),
230472a7 59 'exists $_[0]->{$attr_name}',
8d2d4c67 60 '... got the right code for get_slot_value');
61
62 is($C->inline_weaken_slot_value($instance, $slot_name),
ee7c0467 63 'Scalar::Util::weaken( $_[0]->{$attr_name} )',
8d2d4c67 64 '... got the right code for weaken_slot_value');
65
66 is($C->inline_strengthen_slot_value($instance, $slot_name),
ee7c0467 67 '$_[0]->{$attr_name} = $_[0]->{$attr_name}',
8d2d4c67 68 '... got the right code for strengthen_slot_value');
69}
70
ee7c0467 71my $accessor_string = "sub {\n"
72. $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
73. " if scalar \@_ == 2;\n"
74. $C->inline_get_slot_value('$_[0]', '$attr_name')
75. ";\n}";
76
8d2d4c67 77is($accessor_string,
ee7c0467 78 q|sub {
79$_[0]->{$attr_name} = $_[1] if scalar @_ == 2;
230472a7 80$_[0]->{$attr_name};
8d2d4c67 81}|,
ee7c0467 82 '... got the right code string for accessor');
83
84my $reader_string = "sub {\n"
85. $C->inline_get_slot_value('$_[0]', '$attr_name')
86. ";\n}";
87
8d2d4c67 88is($reader_string,
ee7c0467 89 q|sub {
230472a7 90$_[0]->{$attr_name};
8d2d4c67 91}|,
ee7c0467 92 '... got the right code string for reader');
8d2d4c67 93
ee7c0467 94my $writer_string = "sub {\n"
95. $C->inline_set_slot_value('$_[0]', '$attr_name', '$_[1]')
96. ";\n}";
97
8d2d4c67 98is($writer_string,
ee7c0467 99 q|sub {
100$_[0]->{$attr_name} = $_[1];
8d2d4c67 101}|,
102 '... got the right code string for writer');
103
104