blib/lib/Parallel/ForkManager/Segmented/Base.pm

filter: Statementstmt 24.3% 10 / 41 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 37.5% 3 / 8 Podpod 100% 2 / 2 totaltotal 19.7% 15 / 76 SCAR 42.2
CC
10
Cov
17%
process_args
72.0
__ANON__
6.0
__ANON__
6.0
CRAP 67.9
↑ Summary Build »
1 package Parallel::ForkManager::Segmented::Base;
2 1 $Parallel::ForkManager::Segmented::Base::VERSION = '0.2.1';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new
8 {
9 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
10  
11 0 my $self = bless {}, $class;
12  
13 0 $self->_init(@_);
14  
15 0 return $self;
16 }
17  
18 sub _init
19 {
20 0 ▶ my ( $self, $args ) = @_;
Subroutine _init: not called CC=1 SCAR=6.9
21  
22 0 return;
23 }
24  
25 sub process_args
26 {
27 0 ▶ my ( $self, $args ) = @_;
Subroutine process_args: not called CC=8 SCAR=42.8
Pod documented
28  
29 0 my $WITH_PM = !$args->{disable_fork};
30 0 my $items = $args->{items};
31 0 my $stream_cb = $args->{stream_cb};
32 0 my $cb = $args->{process_item};
33 0 my $batch_cb = $args->{process_batch};
34  
35 0 ▶ if ( $stream_cb && $items )
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_cb and $items) 0 0 0
Condition0%0/3
$stream_cb and $items
!ll&&!rl&&r
000
MC/DC0%0/2
$stream_cb and $items
$stream_cb $items
Truth table0%0/3
A and B
A= $stream_cbB= $items
ABresult
0X0
100
111
36 {
37 0 die "Do not specify both stream_cb and items!";
38 }
39 0 ▶ if ( $batch_cb && $cb )
Branch: 1 branch
BranchTrueFalseTotal
if ($batch_cb and $cb) 0 0 0
Condition0%0/3
$batch_cb and $cb
!ll&&!rl&&r
000
MC/DC0%0/2
$batch_cb and $cb
$batch_cb $cb
Truth table0%0/3
A and B
A= $batch_cbB= $cb
ABresult
0X0
100
111
40 {
41 0 die "Do not specify both process_item and process_batch!";
42 }
43 $batch_cb //= sub {
44 0 ▶ foreach my $item ( @{ shift() } )
Subroutine __ANON__: not called CC=2 SCAR=17.9
45 {
46 0 $cb->($item);
47 }
48 0 return;
49 0 ▶ };
Condition0%0/3
$batch_cb //= sub { foreach my $item (@{shift();}) { &$cb($item); } ; return; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$batch_cb //= sub { foreach my $item (@{shift();}) { &$cb($item); } ; return; }
$batch_cb sub { foreach my $item (@{shift();}) { &$cb($item); } ; return; }
Truth table0%0/3
A //= B
A= $batch_cbB= sub { foreach my $item (@{shift();}) { &$cb($item); } ; return; }
ABresult
1X1
011
000
50 0 my $nproc = $args->{nproc};
51 0 my $batch_size = $args->{batch_size};
52  
53 # Return prematurely on empty input to avoid calling $ch with undef()
54 # at least once.
55 0 ▶ if ($items)
Branch: 1 branch
BranchTrueFalseTotal
if ($items) 0 0 0
56 {
57 0 ▶ if ( not @$items )
Branch: 1 branch
BranchTrueFalseTotal
unless (@$items) 0 0 0
58 {
59 0 return;
60 }
61 $stream_cb = sub {
62 0 ▶ my ($args) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
63 0 my $size = $args->{size};
64  
65 0 ▶ return +{ items =>
Branch: 1 branch
BranchTrueFalseTotal
@$items ? : 0 0 0
66 scalar( @$items ? [ splice @$items, 0, $size ] : undef() ),
67 };
68 0 };
69 }
70 return +{
71 0 WITH_PM => $WITH_PM,
72 batch_cb => $batch_cb,
73 batch_size => $batch_size,
74 nproc => $nproc,
75 stream_cb => $stream_cb,
76 };
77 }
78  
79 1 1;
80  
81 __END__
↑ Summary Build »