Use get_all_attributes instead of the deprecated compute_all_applicable_attributes.
[gitmo/MooseX-Emulate-Class-Accessor-Fast.git] / t / accessors.t
CommitLineData
c5a105b3 1#!perl
2use strict;
30cbeb5e 3use Test::More tests => 33;
4use Test::Exception;
5
6use Class::MOP;
c5a105b3 7
8#1
9require_ok("MooseX::Adopt::Class::Accessor::Fast");
10
11my $class = "Testing::Class::Accessor::Fast";
12
13{
30cbeb5e 14 my $infinite_loop_indicator = 0;
15 my $meta = Class::MOP::Class->create(
16 $class,
17 superclasses => ['Class::Accessor::Fast'],
18 methods => {
19 car => sub { shift->_car_accessor(@_); },
20 mar => sub { return "Overloaded"; },
21 test => sub {
22 die('Infinite loop detected') if $infinite_loop_indicator++;
23 $_[0]->_test_accessor((@_ > 1 ? @_ : ()));
24 }
25 }
26 );
c5a105b3 27
30cbeb5e 28 $class->mk_accessors(qw( foo bar yar car mar test));
c5a105b3 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));
33}
34
13d105cc 35my %attrs = map{$_->name => $_} $class->meta->get_all_attributes;
c5a105b3 36
37#2
30cbeb5e 38is(keys %attrs, 11, 'Correct number of attributes');
c5a105b3 39
40#3-12
41ok(exists $attrs{$_}, "Attribute ${_} created")
42 for qw( foo bar yar car mar static unchanged sekret double_sekret best );
43
44#13-21
30cbeb5e 45ok($class->can("_${_}_accessor"), "Alias method (_${_}_accessor) for ${_} created")
c5a105b3 46 for qw( foo bar yar car mar static unchanged sekret double_sekret );
47
48#22-24
49is( $attrs{$_}->accessor, $_, "Accessor ${_} created" )
50 for qw( foo bar yar);
51
52#25,26
53ok( !$attrs{$_}->has_accessor, "Accessor ${_} not created" )
54 for qw( car mar);
55
56#27,28
57is( $attrs{$_}->reader, $_, "Reader ${_} created")
58 for qw( static unchanged );
59
60#29,30
61is( $attrs{$_}->writer, $_, "Writer ${_} created")
62 for qw(sekret double_sekret);
63
64#31,32
65is( $attrs{'best'}->reader, 'get_best', "Reader get_best created");
66is( $attrs{'best'}->writer, 'set_best', "Writer set_best created");
30cbeb5e 67
68#33
69lives_ok{ $class->new->test(1) } 'no auto-reference to accessors from aliases';