3 use Test::More tests => 33;
9 require_ok("MooseX::Adopt::Class::Accessor::Fast");
11 my $class = "Testing::Class::Accessor::Fast";
14 my $infinite_loop_indicator = 0;
15 my $meta = Class::MOP::Class->create(
17 superclasses => ['Class::Accessor::Fast'],
19 car => sub { shift->_car_accessor(@_); },
20 mar => sub { return "Overloaded"; },
22 die('Infinite loop detected') if $infinite_loop_indicator++;
23 $_[0]->_test_accessor((@_ > 1 ? @_ : ()));
28 $class->mk_accessors(qw( foo bar yar car mar test));
29 $class->mk_ro_accessors(qw(static unchanged));
30 $class->mk_wo_accessors(qw(sekret double_sekret));
31 $class->follow_best_practice;
32 $class->mk_accessors(qw( best));
35 my %attrs = map{$_->name => $_} $class->meta->compute_all_applicable_attributes;
38 is(keys %attrs, 11, 'Correct number of attributes');
41 ok(exists $attrs{$_}, "Attribute ${_} created")
42 for qw( foo bar yar car mar static unchanged sekret double_sekret best );
45 ok($class->can("_${_}_accessor"), "Alias method (_${_}_accessor) for ${_} created")
46 for qw( foo bar yar car mar static unchanged sekret double_sekret );
49 is( $attrs{$_}->accessor, $_, "Accessor ${_} created" )
53 ok( !$attrs{$_}->has_accessor, "Accessor ${_} not created" )
57 is( $attrs{$_}->reader, $_, "Reader ${_} created")
58 for qw( static unchanged );
61 is( $attrs{$_}->writer, $_, "Writer ${_} created")
62 for qw(sekret double_sekret);
65 is( $attrs{'best'}->reader, 'get_best', "Reader get_best created");
66 is( $attrs{'best'}->writer, 'set_best', "Writer set_best created");
69 lives_ok{ $class->new->test(1) } 'no auto-reference to accessors from aliases';