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