Commit | Line | Data |
38bf2a25 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | use Class::MOP; |
5 | |
6 | my $Point = Class::MOP::Class->create('Point' => ( |
7 | version => '0.01', |
8 | attributes => [ |
9 | Class::MOP::Attribute->new('x' => ( |
10 | reader => 'x', |
11 | init_arg => 'x' |
12 | )), |
13 | Class::MOP::Attribute->new('y' => ( |
14 | accessor => 'y', |
15 | init_arg => 'y' |
16 | )), |
17 | ], |
18 | methods => { |
19 | 'new' => sub { |
20 | my $class = shift; |
21 | my $instance = $class->meta->new_object(@_); |
22 | bless $instance => $class; |
23 | }, |
24 | 'clear' => sub { |
25 | my $self = shift; |
26 | $self->{'x'} = 0; |
27 | $self->{'y'} = 0; |
28 | } |
29 | } |
30 | )); |
31 | |
32 | is($Point->get_attribute('x')->insertion_order, 0, 'Insertion order of Attribute "x"'); |
33 | is($Point->get_attribute('y')->insertion_order, 1, 'Insertion order of Attribute "y"'); |
34 | |
f5f4219a |
35 | { |
36 | my $class = Class::MOP::Class->create('Foo'); |
37 | |
38 | $class->add_attribute('first'); |
39 | $class->add_attribute('second'); |
40 | |
41 | is( |
42 | $class->get_attribute('first')->insertion_order, 0, |
43 | 'insertion_order for first is 0' |
44 | ); |
45 | is( |
46 | $class->get_attribute('second')->insertion_order, 1, |
47 | 'insertion_order for second is 1' |
48 | ); |
49 | |
50 | $class->add_attribute('first'); |
51 | |
52 | is( |
53 | $class->get_attribute('first')->insertion_order, 0, |
54 | 'insertion_order for first is still 0 after removing and readding first' |
55 | ); |
56 | |
57 | is( |
58 | $class->get_attribute('second')->insertion_order, 1, |
59 | 'insertion_order for second is still 0 after removing and readding first' |
60 | ); |
61 | } |
62 | |
38bf2a25 |
63 | done_testing; |