line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::tail; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
424
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
345
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
19553
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
2927
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
#use Log::Any '$log'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.572'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
377
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
223
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{tail} = { |
16
|
|
|
|
|
|
|
v => 1.1, |
17
|
|
|
|
|
|
|
summary => 'Output the last items of data', |
18
|
|
|
|
|
|
|
args => { |
19
|
|
|
|
|
|
|
%common_args, |
20
|
|
|
|
|
|
|
items => { |
21
|
|
|
|
|
|
|
summary => 'Number of items to output', |
22
|
|
|
|
|
|
|
schema=>['int*' => {default=>10}], |
23
|
|
|
|
|
|
|
tags => ['main'], |
24
|
|
|
|
|
|
|
cmdline_aliases => { n=>{} }, |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
tags => [qw/filtering/], |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
sub tail { |
30
|
4
|
|
|
4
|
1
|
10
|
my %args = @_; |
31
|
4
|
|
|
|
|
8
|
my ($in, $out) = ($args{in}, $args{out}); |
32
|
4
|
|
100
|
|
|
11
|
my $n = $args{items} // 10; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# maintain temporary buffer first |
35
|
4
|
|
|
|
|
12
|
my @buf; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
14
|
while (my ($index, $item) = each @$in) { |
38
|
80
|
|
|
|
|
85
|
push @buf, $item; |
39
|
80
|
100
|
|
|
|
163
|
shift @buf if @buf > $n; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# push buffer to out |
43
|
4
|
|
|
|
|
11
|
push @$out, $_ for @buf; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
12
|
[200, "OK"]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
# ABSTRACT: Output the last items of data |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |