Commit | Line | Data |
11c0f905 |
1 | #!perl |
2 | package Point; |
3 | use Mouse; |
4 | |
5 | has 'x' => (isa => 'Int', is => 'rw', required => 1); |
6 | has 'y' => (isa => 'Int', is => 'rw', required => 1); |
7 | |
8 | sub clear { |
9 | my $self = shift; |
10 | $self->x(0); |
11 | $self->y(0); |
12 | } |
13 | |
14 | package Point3D; |
15 | use Mouse; |
16 | |
17 | extends 'Point'; |
18 | |
19 | has 'z' => (isa => 'Int', is => 'rw', required => 1); |
20 | |
21 | after 'clear' => sub { |
22 | my $self = shift; |
23 | $self->z(0); |
24 | }; |
25 | |
26 | package main; |
27 | |
28 | # hash or hashrefs are ok for the constructor |
29 | my $point1 = Point->new(x => 5, y => 7); |
30 | my $point2 = Point->new({x => 5, y => 7}); |
31 | |
32 | my $point3d = Point3D->new(x => 5, y => 42, z => -5); |
33 | |
34 | print "point1: ", $point1->dump(); |
35 | print "point2: ", $point2->dump(); |
36 | print "point3: ", $point3d->dump(); |