Data/Unixish/head.pm

filter: Statementstmt 100% 28 / 28 Branchbran 75.0% 3 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 97.6% 41 / 42 CC 4 SCAR 8.5
CC
4
Cov
97%
head
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« Data/Unixish/cat.pm ↑ Summary Data/Unixish/ltrim.pm »
1 package Data::Unixish::head;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use syntax 'each_on_array'; # to support perl < 5.12
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Log::Any '$log';
8  
9 2 ▶use Data::Unixish::Util qw(%common_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 2 our $DATE = '2025-02-24'; # DATE
13 2 our $DIST = 'Data-Unixish'; # DIST
14 2 our $VERSION = '1.574'; # VERSION
15  
16 2 our %SPEC;
17  
18 $SPEC{head} = {
19 2 v => 1.1,
20 summary => 'Output the first items of data',
21 args => {
22 %common_args,
23 items => {
24 summary => 'Number of items to output',
25 schema=>['int*' => {default=>10}],
26 tags => ['main'],
27 cmdline_aliases => { n=>{} },
28 },
29 },
30 tags => [qw/filtering/],
31 };
32 4 ▶sub head {
Subroutine head: called CC=4 SCAR=13.9
Pod documented
33 4 my %args = @_;
34 4 my ($in, $out) = ($args{in}, $args{out});
35 4 ▶ my $n = $args{items} // 10;
Condition100%2/2
$args{"items"} // 10
l!l
31
MC/DC100%1/1
$args{"items"} // 10
$args{"items"}
Truth table100%2/2
A
A= $args{"items"}
Aresult
11
00
36  
37 4 ▶ while (my ($index, $item) = each @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$in) 17 0 17
38 17 ▶ last if $index >= $n;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $n 4 13 17
39 13 push @$out, $item;
40 }
41  
42 4 [200, "OK"];
43 }
44  
45 2 1;
46 # ABSTRACT: Output the first items of data
47  
48 __END__
« Data/Unixish/cat.pm ↑ Summary Data/Unixish/ltrim.pm »