File: closure.t

package info (click to toggle)
libfunction-parameters-perl 2.001003-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 948 kB
  • sloc: perl: 6,478; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 894 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
#!perl
use strict;
use warnings FATAL => 'all';
use Test::More
    eval { require Moose }
    ? (tests => 7)
    : (skip_all => "Moose required for testing types")
;

{
    package Foo;

    use Moose;
    use Function::Parameters {
        fun    => { defaults => 'function', reify_type => 'moose' },
        method => { defaults => 'method',   reify_type => 'moose' },
    };

    for my $meth (qw/foo bar baz/) {
        Foo->meta->add_method("anon_$meth" => method (Str $bar) {
            $meth . $bar
        });

        eval qq{
            method str_$meth (Str \$bar) {
                \$meth . \$bar
            }
        };
        die $@ if $@;
    }
}

can_ok('Foo', map { ("anon_$_", "str_$_") } qw/foo bar baz/);

my $foo = Foo->new;

for my $meth (qw/foo bar baz/) {
    is($foo->${\"anon_$meth"}('bar'), $meth . 'bar');
    is($foo->${\"str_$meth"}('bar'), $meth . 'bar');
}