moooooose
[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 Moose;
15         
16         has '$.x' => (reader   => 'x');
17         has '$.y' => (accessor => 'y');
18         
19         sub clear {
20             my $self = shift;
21             $self->{'$.x'} = 0;
22             $self->y(0);    
23         }
24         
25         package Point3D;
26         use Moose;
27         
28         use base 'Point';
29         
30         has '$:z';
31         
32         sub clear {
33             my $self = shift;
34                 $self->SUPER::clear();
35             $self->{'$:z'} = 0;
36         }
37         
38 }
39
40 my $point = Point->new(x => 1, y => 2); 
41 isa_ok($point, 'Point');
42
43 is($point->x, 1, '... got the right value for x');
44 is($point->y, 2, '... got the right value for y');
45
46 $point->y(10);
47
48 is($point->y, 10, '... got the right (changed) value for y');
49
50 $point->clear();
51
52 is($point->x, 0, '... got the right (cleared) value for x');
53 is($point->y, 0, '... got the right (cleared) value for y');
54
55 my $point3d = Point3D->new(x => 10, y => 15, z => 3);
56 isa_ok($point3d, 'Point3D');
57 isa_ok($point3d, 'Point');
58
59 is($point3d->x, 10, '... got the right value for x');
60 is($point3d->y, 15, '... got the right value for y');
61 is($point3d->{'$:z'}, 3, '... got the right value for z');
62
63 $point3d->clear();
64
65 is($point3d->x, 0, '... got the right (cleared) value for x');
66 is($point3d->y, 0, '... got the right (cleared) value for y');
67 is($point3d->{'$:z'}, 0, '... got the right (cleared) value for z');