blib/lib/List/EachCons.pm

filter: Statementstmt 100% 31 / 31 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 93.3% 42 / 45 CC 6 SCAR 14.0
CC
6
Cov
92%
each_cons
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package List::EachCons;
2
3 3 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 3 our $VERSION = '0.01';
9
10 3 our %EXPORT_TAGS = ( 'all' => [ qw(
11 each_cons
12 ) ] );
13
14 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
15
16 3 our @EXPORT = qw(
17 each_cons
18 );
19
20 1 ▶sub each_cons($\@&) {
Subroutine each_cons: called CC=6 SCAR=18.1
Pod documented
21 1 my ($count, $list, $code) = @_;
22 1 ▶ return unless @$list >= $count;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list >= $count 0 1 1
23 1 ▶ return unless $count > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $count > 0 0 1 1
24 1 my $ix = 0;
25 1 my @current;
26 1 push @current, $list->[$ix++] for 1 .. $count;
27 1 my @result;
28 1 while (1) {
29 2 my $value = $code->(@current);
30 2 ▶ push @result, $value if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 2 0 2
31 2 ▶ last if $ix >= @$list;
Branch: 1 branch
BranchTrueFalseTotal
if $ix >= @$list 1 1 2
32 1 shift @current;
33 1 push @current, $list->[$ix++];
34 }
35 1 @result;
36 }
37
38 3 1;
39
40 __END__
↑ Summary