File Coverage

blib/lib/Data/Unixish/head.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Data::Unixish::head;
2              
3 1     1   553 use 5.010;
  1         6  
4 1     1   6 use strict;
  1         2  
  1         23  
5 1     1   419 use syntax 'each_on_array'; # to support perl < 5.12
  1         24041  
  1         5  
6 1     1   3549 use warnings;
  1         3  
  1         29  
7             #use Log::Any '$log';
8              
9 1     1   449 use Data::Unixish::Util qw(%common_args);
  1         4  
  1         277  
10              
11             our $VERSION = '1.571'; # VERSION
12              
13             our %SPEC;
14              
15             $SPEC{head} = {
16             v => 1.1,
17             summary => 'Output the first 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 head {
30 4     4 1 12 my %args = @_;
31 4         8 my ($in, $out) = ($args{in}, $args{out});
32 4   100     14 my $n = $args{items} // 10;
33              
34 4         15 while (my ($index, $item) = each @$in) {
35 17 100       35 last if $index >= $n;
36 13         29 push @$out, $item;
37             }
38              
39 4         15 [200, "OK"];
40             }
41              
42             1;
43             # ABSTRACT: Output the first items of data
44              
45             __END__