1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test::More;
BEGIN {
$] >= 5.026000 or plan skip_all => "No parse_subsignature()";
}
use Feature::Compat::Class;
class List {
field @values;
method push ( @more ) { push @values, @more }
method nshift ( $n ) { splice @values, 0, $n }
}
{
my $l = List->new;
$l->push(qw( a b c d ));
is_deeply( [ $l->nshift( 2 ) ],
[qw( a b )],
'$l->nshift yields values' );
}
class Test2 {
field $name;
ADJUST { $name = "Unit test" }
method greet ( $message = "Hello, $name" ) {
return $message;
}
}
{
my $obj = Test2->new;
is( $obj->greet, "Hello, Unit test",
'subroutine signature default exprs can see instance fields'
);
}
done_testing;
|