3 use Test::More tests => 25;
5 use warnings FATAL => 'all';
8 use Function::Parameters { fun => 'function_strict', method => 'method_strict' };
13 method new($class : ) {
21 method get_x() { $self->{x} }
22 method get_y($self:) { $self->{y} }
23 method get_z($this:) { $this->{z} }
25 method set_x($val) { $self->{x} = $val; }
26 method set_y($self:$val) { $self->{y} = $val; }
27 method set_z($this: $val) { $this->{z} = $val; }
31 ok $o->isa('Foo'), "Foo->new->isa('Foo')";
45 is eval { $o->get_z(42) }, undef;
46 like $@, qr/many arguments/;
48 is eval { $o->set_z }, undef;
49 like $@, qr/enough arguments/;
51 is eval q{fun ($self:) {}}, undef;
52 like $@, qr/invocant/;
54 is eval q{fun ($x : $y) {}}, undef;
55 like $@, qr/invocant/;
57 is eval q{method (@x:) {}}, undef;
58 like $@, qr/invocant/;
60 is eval q{method (%x:) {}}, undef;
61 like $@, qr/invocant/;
64 use Function::Parameters {
70 def foo1($x) { join ' ', $x, @_ }
71 def foo2($x: $y) { join ' ', $x, $y, @_ }
72 def foo3($x, $y) { join ' ', $x, $y, @_ }
75 is foo2("a", "b"), "a b b";
76 is foo3("a", "b"), "a b a b";
77 is foo1("a", "b"), "a a b";
78 is foo2("a", "b", "c"), "a b b c";
79 is foo3("a", "b", "c"), "a b a b c";