1 package Variable::Magic::TestThreads;
6 use Config qw<%Config>;
8 use Variable::Magic qw<VMG_THREADSAFE>;
13 Test::More::plan(skip_all => $msg);
24 skipall 'This Variable::Magic isn\'t thread safe' unless VMG_THREADSAFE;
26 my $force = $ENV{PERL_VARIABLE_MAGIC_TEST_THREADS} ? 1 : !1;
27 skipall 'This perl wasn\'t built to support threads'
28 unless $Config{useithreads};
29 skipall 'perl 5.13.4 required to test thread safety'
30 unless $force or "$]" >= 5.013004;
32 my $t_v = $force ? '0' : '1.67';
33 my $has_threads = do {
35 eval "use threads $t_v; 1";
37 skipall "threads $t_v required to test thread safety" unless $has_threads;
39 my $ts_v = $force ? '0' : '1.14';
40 my $has_threads_shared = do {
42 eval "use threads::shared $ts_v; 1";
44 skipall "threads::shared $ts_v required to test thread safety"
45 unless $has_threads_shared;
47 defined and diag "Using threads $_" for $threads::VERSION;
48 defined and diag "Using threads::shared $_" for $threads::shared::VERSION;
55 while (my ($name, $code) = each %exports) {
57 *{$pkg.'::'.$name} = $code;
65 local $SIG{__WARN__} = sub { push @diag, "Thread creation warning: @_" };
68 push @diag, "Thread creation error: $@" if $@;
71 Test::More::diag($_) for @diag;
73 return $thread ? $thread : ();