blib/lib/App/Netdisco/Util/MCE.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 64 CC 9 SCAR 31.3
CC
9
Cov
0%
_scale_ncpu
42.0
parse_max_workers
20.0
prctl
2.0
CRAP 22.8
1 package App::Netdisco::Util::MCE;
2  
3 use strict;
4 use warnings;
5  
6 use MCE::Util ();
7  
8 use base 'Exporter';
9 our @EXPORT = qw/prctl parse_max_workers/;
10  
11 sub prctl { $0 = shift }
12  
13 sub parse_max_workers {
14 my $max = shift;
15 return 0 if !defined $max;
16  
17 if ($max =~ /^auto(?:$|\s*([\-\+\/\*])\s*(.+)$)/i) {
18 my $ncpu = MCE::Util::get_ncpu() || 0;
19  
20 if ($1 and $2) {
21 my ($op, $operand) = ($1, $2);
22 $max = _scale_ncpu($ncpu, $op, $operand);
23 }
24 }
25  
26 return $max || 0;
27 }
28  
29 # the forms MCE itself documents: auto, auto*1.5, auto/2.0, auto+3, auto-1
30 sub _scale_ncpu {
31 my ($ncpu, $op, $operand) = @_;
32 return 0 unless $operand =~ m/^(\d+(?:\.\d*)?|\.\d+)\s*$/;
33 my $num = $1;
34  
35 my $scaled = ($op eq '+') ? $ncpu + $num
36 : ($op eq '-') ? $ncpu - $num
37 : ($op eq '*') ? $ncpu * $num
38 : ($num == 0) ? 0
39 : $ncpu / $num;
40  
41 return int($scaled + 0.5);
42 }
43  
44 1;