Data/Unixish/tail.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 4 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 44 / 44 CC 5 SCAR 11.0
CC
5
Cov
100%
tail
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Data/Unixish/trunc.pm ↑ Summary Data/Unixish/trim.pm »
1 package Data::Unixish::tail;
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 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10 2 our $DATE = '2025-02-24'; # DATE
11 2 our $DIST = 'Data-Unixish'; # DIST
12 2 our $VERSION = '1.574'; # VERSION
13  
14 2 ▶use Data::Unixish::Util qw(%common_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our %SPEC;
17  
18 $SPEC{tail} = {
19 2 v => 1.1,
20 summary => 'Output the last 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 tail {
Subroutine tail: called CC=5 SCAR=16.1
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 # maintain temporary buffer first
38 4 my @buf;
39  
40 4 ▶ while (my ($index, $item) = each @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$in) 80 4 84
41 80 push @buf, $item;
42 80 ▶ shift @buf if @buf > $n;
Branch: 1 branch
BranchTrueFalseTotal
if @buf > $n 67 13 80
43 }
44  
45 # push buffer to out
46 4 push @$out, $_ for @buf;
47  
48 4 [200, "OK"];
49 }
50  
51 2 1;
52 # ABSTRACT: Output the last items of data
53  
54 __END__
« Data/Unixish/trunc.pm ↑ Summary Data/Unixish/trim.pm »