use v5.20;
use experimental 'signatures';
package Point {
sub new ($class, $x, $y) {
bless [$x, $y] => $class;
}
sub x ($self) { $self->[0] }
sub y ($self) { $self->[1] }
sub inverted ($self) {
ref($self)->new($self->y, $self->x);
}
}
####
my Foo $foo = Foo->new(...);
##
##
sub foo (Int $bar, Str $baz) {
...;
}
##
##
sub foo {
my Int $bar = $_[0];
my Str $baz = $_[1];
die "..." if @_ > 2;
...;
}
##
##
my Foo $x = $y;
##
##
"Foo"->CHECK_SCALAR(\$newvalue);
Foo()->CHECK_SCALAR(\$newvalue);
##
##
sub UNIVERSAL::CHECK_SCALAR (Str $class, ScalarRef $sref) {
require Scalar::Util;
unless (Scalar::Util::blessed($$sref) && ${$sref}->isa($class)) {
require Carp;
Carp::croak("...");
}
}