Джерело:
blogs.perl.org
Дата публікації:
23/09/2022 06:08
Постійна адреса новини:
http://www.vsinovyny.com/9336664
23/09/2022 06:08 // blogs.perl.org
Class::Plain provides a class syntax for the hash-based Perl OO.
use Class::Plain; class Point { field x; field y; method new : common { my $self = $class->SUPER::new(@_); $self->{x} //= 0; $self->{y} //= 0; return $self; } method move { my ($x, $y) = @_; $self->{x} += $x; $self->{y} += $y; } method describe { print "A point at ($self->{x}, $self->{y})\n"; } } my $point = Point->new(x => 5, y => 10); $point->describe;
Inheritance:
class Point3D : isa(Point) { field z; method new : common { my $self = $class->SUPER::new(@_); $self->{z} //= 0; return $self; } method move { my ($x, $y, $z) = @_; $self->SUPER::move($x, $y); $self->{z} += $z; } method describe { print "A point at ($self->{x}, $self->{y}, $self->{z})\n"; } } my $point3d = Point3D->new(x => 5, y => 10, z => 15); $point3d->describe;
See also the Class::Plain document and the cookbook.
Class::Plain was released at 2022-09-22.
I'm strongly interested in Perl OO. I study Corinna and Object::Pad now.
« |
Наступна новина з архіву Киев предложил россиянам сдаваться |
Попередня новина з архіву Конгрес США наполягає на постачанні безпілотників Gray Eagle в Україну |
» | |
|
||||