File: threads.t

package info (click to toggle)
libfunction-parameters-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: perl: 3,945; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 574 bytes parent folder | download | duplicates (3)
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
#!perl

use Test::More
    eval { require threads; threads->import; 1 }
        ? (tests => 2)
        : (skip_all => "threads required for testing threads");

use warnings FATAL => 'all';
use strict;

use Function::Parameters;

fun concat3($x, $xxx, $xx) {
    my $helper = eval q{
        fun ($x, $y) { $x . $y }
    };
    return $x . $helper->($xxx, $xx);
}

my $thr = threads->create(fun ($val) {
    concat3 'first (', $val, ') last';
}, 'middle');

my $r1 = concat3 'foo', threads->tid, 'bar';
my $r2 = $thr->join;

is $r1, 'foo0bar';
is $r2, 'first (middle) last';