File: 11method-signatures.t

package info (click to toggle)
libfeature-compat-class-perl 0.07-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 434; makefile: 2; sh: 1
file content (45 lines) | stat: -rw-r--r-- 746 bytes parent folder | download | duplicates (2)
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;