1#!perl 2use strict; 3use Test::More tests => 12; 4 5my $class = 'Class::Accessor::Fast::Contained'; 6 7require_ok($class); 8my $silly = "Silly::$class"; 9{ 10 no strict 'refs'; 11 @{"${silly}::ISA"} = ($class); 12 *{"${silly}::accessor_name_for"} = sub { "read_$_[1]" }; 13 *{"${silly}::mutator_name_for"} = sub { "write_$_[1]" }; 14 $silly->mk_accessors(qw( foo )); 15 $silly->mk_ro_accessors(qw(roro)); 16 $silly->mk_wo_accessors(qw(wowo)); 17} 18 19for my $f (qw/foo roro /) { 20 ok $silly->can("read_$f"), "'read_$f' method exists"; 21} 22 23for my $f (qw/foo wowo/) { 24 ok $silly->can("write_$f"), "'write_$f' method exists"; 25} 26 27for my $f (qw/foo roro wowo write_roro read_wowo/) { 28 ok !$silly->can($f), "no '$f' method"; 29} 30 31my $test = $silly->new({ 32 foo => "bar", 33 roro => "boat", 34 wowo => "huh", 35 }); 36 37is($test->read_foo, "bar", "initial foo"); 38$test->write_foo("stuff"); 39is($test->read_foo, "stuff", "new foo"); 40