fucking attributes dont work right ,... damn you perl,.. damn you
[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         after 'clear' => sub {
33             my $self = shift;
34             $self->{'$:z'} = 0;
35         };
36         
37 }
38
39 my $point = Point->new(x => 1, y => 2); 
40 isa_ok($point, 'Point');
41
42 is($point->x, 1, '... got the right value for x');
43 is($point->y, 2, '... got the right value for y');
44
45 $point->y(10);
46
47 is($point->y, 10, '... got the right (changed) value for y');
48
49 $point->clear();
50
51 is($point->x, 0, '... got the right (cleared) value for x');
52 is($point->y, 0, '... got the right (cleared) value for y');
53
54 my $point3d = Point3D->new(x => 10, y => 15, z => 3);
55 isa_ok($point3d, 'Point3D');
56 isa_ok($point3d, 'Point');
57
58 is($point3d->x, 10, '... got the right value for x');
59 is($point3d->y, 15, '... got the right value for y');
60 is($point3d->{'$:z'}, 3, '... got the right value for z');
61
62 $point3d->clear();
63
64 is($point3d->x, 0, '... got the right (cleared) value for x');
65 is($point3d->y, 0, '... got the right (cleared) value for y');
66 is($point3d->{'$:z'}, 0, '... got the right (cleared) value for z');