Perl 5.36.0 synopsis doesn't work for 'class' feature

I’m trying to execute the following script, which is taken from Perl’s documentation:

use v5.36;
use feature 'class';

class My::Example 1.234 {
    field $x;

    ADJUST {
        $x = "Hello, world";
    }

    method print_message {
        say $x;
    }
}

My::Example->new->print_message;

However, I’m getting the following error:

Feature "class" is not supported by Perl 5.36.0 at /home/con/Scripts/class.pl line 4.
BEGIN failed--compilation aborted at /home/con/Scripts/class.pl line 4.
Command exited with non-zero status 255

Is this a bug in Perl’s documentation, or am I doing something wrong?

The class feature is not supported in Perl 5.36.0. The documentation you are referring to is likely outdated or for a different version of Perl. To fix the issue, you can remove the use feature 'class'; line and modify the script as follows:

use v5.36;
use strict;
use warnings;

{
    package My::Example;
    use fields qw($x);

    sub new {
        my $class = shift;
        my $self = fields::new($class);
        return $self;
    }

    sub ADJUST {
        my $self = shift;
        $self->{x} = "Hello, world";
    }

    sub print_message {
        my $self = shift;
        say $self->{x};
    }
}

My::Example->new->print_message;

This script uses the fields pragma to define a class with a single field $x. The ADJUST method sets the value of $x, and the print_message method prints the value of $x.

By making these changes, you should be able to execute the script without any errors.