From: gfx Date: Tue, 3 Nov 2009 06:18:27 +0000 (+0900) Subject: Add a example script X-Git-Tag: 0.40_06~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=11c0f905bc3cdaa68afd53263b90e3b0e1ce4e5c;p=gitmo%2FMouse.git Add a example script --- diff --git a/example/point.pl b/example/point.pl new file mode 100644 index 0000000..d85df30 --- /dev/null +++ b/example/point.pl @@ -0,0 +1,36 @@ +#!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();