more tests
[gitmo/Moose.git] / t / 001_basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 15;
7
8 BEGIN {
9     use_ok('Moose');           
10 }
11
12 {
13         package Point;
14         use strict;
15         use warnings;   
16         use Moose;
17         
18         has '$.x' => (reader   => 'x');
19         has '$.y' => (accessor => 'y');
20         
21         sub clear {
22             my $self = shift;
23             $self->{'$.x'} = 0;
24             $self->y(0);    
25         }
26         
27         package Point3D;
28         use strict;
29         use warnings;
30         use Moose;
31         
32         use base 'Point';
33         
34         has '$:z';
35         
36         after 'clear' => sub {
37             my $self = shift;
38             $self->{'$:z'} = 0;
39         };
40         
41 }
42
43 my $point = Point->new(x => 1, y => 2); 
44 isa_ok($point, 'Point');
45
46 is($point->x, 1, '... got the right value for x');
47 is($point->y, 2, '... got the right value for y');
48
49 $point->y(10);
50
51 is($point->y, 10, '... got the right (changed) value for y');
52
53 $point->clear();
54
55 is($point->x, 0, '... got the right (cleared) value for x');
56 is($point->y, 0, '... got the right (cleared) value for y');
57
58 my $point3d = Point3D->new(x => 10, y => 15, z => 3);
59 isa_ok($point3d, 'Point3D');
60 isa_ok($point3d, 'Point');
61
62 is($point3d->x, 10, '... got the right value for x');
63 is($point3d->y, 15, '... got the right value for y');
64 is($point3d->{'$:z'}, 3, '... got the right value for z');
65
66 $point3d->clear();
67
68 is($point3d->x, 0, '... got the right (cleared) value for x');
69 is($point3d->y, 0, '... got the right (cleared) value for y');
70 is($point3d->{'$:z'}, 0, '... got the right (cleared) value for z');