File: point.pl

package info (click to toggle)
libmouse-perl 2.5.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,160 kB
  • sloc: perl: 14,614; ansic: 218; makefile: 8
file content (40 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!perl
package Point;
use Mouse;

has 'x' => (isa => 'Int', is => 'rw', required => 1);
has 'y' => (isa => 'Int', is => 'rw', required => 1);

sub clear {
  my $self = shift;
  $self->x(0);
  $self->y(0);
}

package Point3D;
use Mouse;

extends 'Point';

has 'z' => (isa => 'Int', is => 'rw', required => 1);

after 'clear' => sub {
  my $self = shift;
  $self->z(0);
};

package main;

# hash or hashrefs are ok for the constructor
my $point1 = Point->new(x => 5, y => 7);
my $point2 = Point->new({x => 5, y => 7});

my $point3d = Point3D->new(x => 5, y => 42, z => -5);

print "point1: ", $point1->dump();
print "point2: ", $point2->dump();
print "point3: ", $point3d->dump();

print "point3d->clear()\n";
$point3d->clear();
print "point3: ", $point3d->dump();