Commit | Line | Data |
c5a105b3 |
1 | #!perl |
2 | use strict; |
3 | use Test::More tests => 32; |
4 | |
5 | #1 |
6 | require_ok("MooseX::Adopt::Class::Accessor::Fast"); |
7 | |
8 | my $class = "Testing::Class::Accessor::Fast"; |
9 | |
10 | { |
11 | no strict 'refs'; |
12 | @{"${class}::ISA"} = ('Class::Accessor::Fast'); |
13 | *{"${class}::car"} = sub { shift->_car_accessor(@_); }; |
14 | *{"${class}::mar"} = sub { return "Overloaded"; }; |
15 | |
16 | $class->mk_accessors(qw( foo bar yar car mar )); |
17 | $class->mk_ro_accessors(qw(static unchanged)); |
18 | $class->mk_wo_accessors(qw(sekret double_sekret)); |
19 | $class->follow_best_practice; |
20 | $class->mk_accessors(qw( best)); |
21 | } |
22 | |
23 | my %attrs = map{$_->name => $_} $class->meta->compute_all_applicable_attributes; |
24 | |
25 | #2 |
26 | is(keys %attrs, 10, 'Correct number of attributes'); |
27 | |
28 | #3-12 |
29 | ok(exists $attrs{$_}, "Attribute ${_} created") |
30 | for qw( foo bar yar car mar static unchanged sekret double_sekret best ); |
31 | |
32 | #13-21 |
33 | ok($class->can("_${_}_accessor"), "Attribute ${_} created") |
34 | for qw( foo bar yar car mar static unchanged sekret double_sekret ); |
35 | |
36 | #22-24 |
37 | is( $attrs{$_}->accessor, $_, "Accessor ${_} created" ) |
38 | for qw( foo bar yar); |
39 | |
40 | #25,26 |
41 | ok( !$attrs{$_}->has_accessor, "Accessor ${_} not created" ) |
42 | for qw( car mar); |
43 | |
44 | #27,28 |
45 | is( $attrs{$_}->reader, $_, "Reader ${_} created") |
46 | for qw( static unchanged ); |
47 | |
48 | #29,30 |
49 | is( $attrs{$_}->writer, $_, "Writer ${_} created") |
50 | for qw(sekret double_sekret); |
51 | |
52 | #31,32 |
53 | is( $attrs{'best'}->reader, 'get_best', "Reader get_best created"); |
54 | is( $attrs{'best'}->writer, 'set_best', "Writer set_best created"); |