fucking attributes dont work right ,... damn you perl,.. damn you
[gitmo/Moose.git] / t / 001_basic.t
CommitLineData
fcd84ca9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 15;
7
8BEGIN {
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
3c7278fb 32 after 'clear' => sub {
fcd84ca9 33 my $self = shift;
fcd84ca9 34 $self->{'$:z'} = 0;
3c7278fb 35 };
fcd84ca9 36
37}
38
39my $point = Point->new(x => 1, y => 2);
40isa_ok($point, 'Point');
41
42is($point->x, 1, '... got the right value for x');
43is($point->y, 2, '... got the right value for y');
44
45$point->y(10);
46
47is($point->y, 10, '... got the right (changed) value for y');
48
49$point->clear();
50
51is($point->x, 0, '... got the right (cleared) value for x');
52is($point->y, 0, '... got the right (cleared) value for y');
53
54my $point3d = Point3D->new(x => 10, y => 15, z => 3);
55isa_ok($point3d, 'Point3D');
56isa_ok($point3d, 'Point');
57
58is($point3d->x, 10, '... got the right value for x');
59is($point3d->y, 15, '... got the right value for y');
60is($point3d->{'$:z'}, 3, '... got the right value for z');
61
62$point3d->clear();
63
64is($point3d->x, 0, '... got the right (cleared) value for x');
65is($point3d->y, 0, '... got the right (cleared) value for y');
66is($point3d->{'$:z'}, 0, '... got the right (cleared) value for z');