Implement strict constructors, which will warn unkown constructor arguments
[gitmo/Mouse.git] / example / point.pl
CommitLineData
11c0f905 1#!perl
2package Point;
3use Mouse;
4
5has 'x' => (isa => 'Int', is => 'rw', required => 1);
6has 'y' => (isa => 'Int', is => 'rw', required => 1);
7
8sub clear {
9 my $self = shift;
10 $self->x(0);
11 $self->y(0);
12}
13
14package Point3D;
15use Mouse;
16
17extends 'Point';
18
19has 'z' => (isa => 'Int', is => 'rw', required => 1);
20
21after 'clear' => sub {
22 my $self = shift;
23 $self->z(0);
24};
25
26package main;
27
28# hash or hashrefs are ok for the constructor
29my $point1 = Point->new(x => 5, y => 7);
30my $point2 = Point->new({x => 5, y => 7});
31
32my $point3d = Point3D->new(x => 5, y => 42, z => -5);
33
34print "point1: ", $point1->dump();
35print "point2: ", $point2->dump();
36print "point3: ", $point3d->dump();
31e71b65 37
38print "point3d->clear()\n";
39$point3d->clear();
40print "point3: ", $point3d->dump();