File: sub-defer-threads.t

package info (click to toggle)
libmoo-perl 1.006001-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 772 kB
  • ctags: 202
  • sloc: perl: 2,348; sh: 18; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 673 bytes parent folder | download
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
use Config;
BEGIN {
  unless ($Config{useithreads}) {
    print "1..0 # SKIP your perl does not support ithreads\n";
    exit 0;
  }
}
use threads;
use strictures 1;
use Test::More;

use Sub::Defer;

my %made;

my $one_defer = defer_sub 'Foo::one' => sub {
  die "remade - wtf" if $made{'Foo::one'};
  $made{'Foo::one'} = sub { 'one' }
};

is(threads->create(sub {
  my $info = Sub::Defer::defer_info($one_defer);
  $info && $info->[0];
})->join, 'Foo::one', 'able to retrieve info in thread');

is(threads->create(sub {
  undefer_sub($one_defer);
  $made{'Foo::one'} && $made{'Foo::one'} == \&Foo::one && 1234;
})->join, 1234, 'able to undefer in thread');

done_testing;