File: 02-use.t

package info (click to toggle)
libmethod-signatures-simple-perl 1.07-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 156 kB
  • sloc: perl: 141; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 560 bytes parent folder | download | duplicates (4)
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

use strict;
use warnings;

use Test::More tests => 7;
use_ok 'Method::Signatures::Simple';

{
    package My::Obj;
    use Method::Signatures::Simple;

    method make($class: %opts) {
        bless {%opts}, $class;
    }
    method first : lvalue {
        $self->{first};
    }
    method second {
        $self->first + 1;
    }
    method nth($inc) {
        $self->first + $inc;
    }
}

my $o = My::Obj->make(first => 1);
is $o->first, 1;
is $o->second, 2;
is $o->nth(10), 11;

$o->first = 10;

is $o->first, 10;
is $o->second, 11;
is $o->nth(10), 20;