blib/lib/Array/Sample/Partition.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 4 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 38 / 38 CC 5 SCAR 11.7
CC
5
Cov
100%
sample_partition
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
↑ Summary
1 package Array::Sample::Partition;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 2 our $DATE = '2022-05-20'; # DATE
11 2 our $DIST = 'Array-Sample-Partition'; # DIST
12 2 our $VERSION = '0.003'; # VERSION
13  
14 2 our @EXPORT_OK = qw(sample_partition);
15  
16 14 ▶sub sample_partition {
Subroutine sample_partition: called CC=5 SCAR=16.1
Pod documented
17 14 my ($ary, $n, $opts) = @_;
18 14 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
212
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
19  
20 14 ▶ $n = @$ary if $n > @$ary;
Branch: 1 branch
BranchTrueFalseTotal
if $n > @$ary 1 13 14
21  
22 14 my @res;
23 14 for my $i (1..$n) {
24 19 my $idx = int($i*@$ary/($n+1));
25 19 ▶ push @res, $opts->{pos} ? $idx : $ary->[$idx];
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'pos'} ? : 3 16 19
26 }
27  
28 14 @res;
29 }
30  
31 2 1;
32 # ABSTRACT: Sample elements from an array by equal partitions
33  
34 __END__
↑ Summary