Commit | Line | Data |
c5a105b3 |
1 | #!perl |
2 | use strict; |
30cbeb5e |
3 | use Test::More tests => 33; |
4 | use Test::Exception; |
5 | |
6 | use Class::MOP; |
c5a105b3 |
7 | |
8 | #1 |
9 | require_ok("MooseX::Adopt::Class::Accessor::Fast"); |
10 | |
11 | my $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 |
35 | my %attrs = map{$_->name => $_} $class->meta->get_all_attributes; |
c5a105b3 |
36 | |
37 | #2 |
30cbeb5e |
38 | is(keys %attrs, 11, 'Correct number of attributes'); |
c5a105b3 |
39 | |
40 | #3-12 |
41 | ok(exists $attrs{$_}, "Attribute ${_} created") |
42 | for qw( foo bar yar car mar static unchanged sekret double_sekret best ); |
43 | |
44 | #13-21 |
30cbeb5e |
45 | ok($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 |
49 | is( $attrs{$_}->accessor, $_, "Accessor ${_} created" ) |
50 | for qw( foo bar yar); |
51 | |
52 | #25,26 |
53 | ok( !$attrs{$_}->has_accessor, "Accessor ${_} not created" ) |
54 | for qw( car mar); |
55 | |
56 | #27,28 |
57 | is( $attrs{$_}->reader, $_, "Reader ${_} created") |
58 | for qw( static unchanged ); |
59 | |
60 | #29,30 |
61 | is( $attrs{$_}->writer, $_, "Writer ${_} created") |
62 | for qw(sekret double_sekret); |
63 | |
64 | #31,32 |
65 | is( $attrs{'best'}->reader, 'get_best', "Reader get_best created"); |
66 | is( $attrs{'best'}->writer, 'set_best', "Writer set_best created"); |
30cbeb5e |
67 | |
68 | #33 |
69 | lives_ok{ $class->new->test(1) } 'no auto-reference to accessors from aliases'; |