The progress of the new class feature of Perl

I introduce the progress of the new class feature of Perl. If you are interested in the progress of the new class feature of Perl, please see the following topics.

p5p Mailing List

Pre-PR Preview of `use feature 'class'`

Trial of the implementation

leonerd/perl5/feature-class | Github

Specification

Corinna RFC

In the current spec, the new class syntax is the following codes.

use feature 'class';

class Point {
  field $x :param :reader :writer;
  field $y :param :reader :writer;

  method clear() {
    $x = 0;
    $y = 0;
  }

  method move ($offset_x, $offset_y) {
    $x += $offset_x;
    $y += $offset_x;
  }
}

class Point3D :isa(Point) {
  field $z :param :reader :writer;

  method clear() {
    $self->next::method;
    $z = 0;
  }

  method move ($offset_x, $offset_y, $offset_z) {
    $self->next::method($offset_x, $offset_y);
    $z += $offset_z;
  }
}

my $point3d = Point3D->new(1, 2, 3);
$point3d->clear;

The discussion and the question

Github Issue

Github Discussion

Interesting Topics

To Twigil or Not To Twigil

To Twigil or Not To Twigil

field $x;

vs

field $:x;

The current spec of Corrina adapts no-twigil, but the last comment.

Closing this ticket. We won't do this for v1, but perhaps it will be revisited later.


has vs field vs slot

Attribute feedback

The current spec of Corrina adapts "field" keyword to define fields.

Field Access Control - Private field only vs more access control

Clarify the scoping nature of fields

For example, the concept of private, public, protected in Java language.

The current spec of Corrina adapts private field only.

Leave a comment

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.