| 1 | package Test::SharedFork; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use base 'Test::Builder::Module'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | our $VERSION = '0.35'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use Test::Builder 0.32; # 0.32 or later is needed | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | use Test::SharedFork::Scalar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use Test::SharedFork::Array; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use Test::SharedFork::Store; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 31 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | ▶ | use 5.008000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | package # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | Test::SharedFork::Contextual; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $wantarray = [caller(1)]->[5]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my @result = $code->(); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | bless {result => \@result, wantarray => $wantarray}, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } elsif (defined $wantarray) { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $result = $code->(); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | bless {result => $result, wantarray => $wantarray}, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | { ; $code->(); } # void context | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | bless {wantarray => $wantarray}, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($self->{wantarray}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return @{ $self->{result} }; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } elsif (defined $self->{wantarray}) { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $self->{result}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 31 | my $STORE; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | ▶ | sub _mangle_builder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mangle_builder: called CC=16 SCAR=49.4
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 35 | my $builder = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 35 | ▶ | if( $] >= 5.008001 && $Config{useithreads} && $INC{'threads.pm'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$] >= "5.008001" and $Test::SharedFork::Config{"useithreads"} and $INC{"threads.pm"}
$] >= "5.008001" and $Test::SharedFork::Config{"useithreads"}
MC/DC0%0/3
$] >= "5.008001" and $Test::SharedFork::Config{"useithreads"} and $INC{"threads.pm"}
$] >= "5.008001"
$Test::SharedFork::Config{"useithreads"}
$INC{"threads.pm"}
Truth table25%1/4
A and B and C
A= $] >= "5.008001"B= $Test::SharedFork::Config{"useithreads"}C= $INC{"threads.pm"}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | die "# Current version of Test::SharedFork does not supports ithreads."; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 35 | ▶ | if ($builder->can("coordinate_forks")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Use Test::Builder's implementation. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 35 | $builder->new->coordinate_forks(1); | |||||||||||||||||||||||||||||||||||||||||
| 56 | ▶ | } elsif($INC{'Test2/Global.pm'} || $INC{'Test2/API.pm'} || $INC{'Test2/Context.pm'}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$INC{"Test2/Global.pm"} or $INC{"Test2/API.pm"} or $INC{"Test2/Context.pm"}
$INC{"Test2/Global.pm"} or $INC{"Test2/API.pm"}
MC/DC0%0/3
$INC{"Test2/Global.pm"} or $INC{"Test2/API.pm"} or $INC{"Test2/Context.pm"}
$INC{"Test2/Global.pm"}
$INC{"Test2/API.pm"}
$INC{"Test2/Context.pm"}
Truth table0%0/4
A or B or C
A= $INC{"Test2/Global.pm"}B= $INC{"Test2/API.pm"}C= $INC{"Test2/Context.pm"}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | require Test2::Global; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | Test2::Global::test2_ipc_enable_polling(); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Check if we already have IPC | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $stack = $builder->{Stack}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return if $stack->top->ipc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Find a driver | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($driver) = Test2::Global::test2_ipc_drivers(); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | unless ($driver) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | require Test2::IPC::Driver::Files; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $driver = 'Test2::IPC::Driver::Files'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Add the IPC to all hubs | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $ipc = $driver->new(); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | for my $hub (@$stack) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $hub->set_ipc($ipc); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $ipc->add_hub($hub->hid); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } elsif($INC{'Test/Stream/Sync.pm'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | require Test::Stream::IPC; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | Test::Stream::IPC->import('poll'); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | Test::Stream::IPC->enable_polling if Test::Stream::IPC->can('enable_polling'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $stack = $builder->{Stack}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return if $stack->top->ipc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($driver) = Test::Stream::IPC->drivers; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $ipc = $driver->new(); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | for my $hub (@$stack) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $hub->set_ipc($ipc); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $ipc->add_hub($hub->hid); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # older Test::Builder | ||||||||||||||||||||||||||||||||||||||||||
| 92 | $STORE = Test::SharedFork::Store->new( | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | cb => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $store = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | tie $builder->{Curr_Test}, 'Test::SharedFork::Scalar', | |||||||||||||||||||||||||||||||||||||||||
| 96 | $store, 'Curr_Test'; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | tie $builder->{Is_Passing}, 'Test::SharedFork::Scalar', | |||||||||||||||||||||||||||||||||||||||||
| 98 | $store, 'Is_Passing'; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | tie @{ $builder->{Test_Results} }, | |||||||||||||||||||||||||||||||||||||||||
| 100 | 'Test::SharedFork::Array', $store, 'Test_Results'; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | init => +{ | ||||||||||||||||||||||||||||||||||||||||||
| 103 | Test_Results => $builder->{Test_Results}, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | Curr_Test => $builder->{Curr_Test}, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | Is_Passing => 1, | |||||||||||||||||||||||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # make methods atomic. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 31 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 31 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 31 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | for my $name (qw/ok skip todo_skip current_test is_passing/) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $orig = *{"Test::Builder::${name}"}{CODE}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | *{"Test::Builder::${name}"} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | local $Test::Builder::BLevel = $Test::Builder::BLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $lock = $STORE->get_lock(); # RAII | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $orig->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 31 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 31 | my $builder = __PACKAGE__->builder; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 31 | _mangle_builder($builder); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # backward compatibility method | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub parent { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | sub child { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
child: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 74 | ▶ | sub fork { fork() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fork: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||||||||||||||||