File Coverage

blib/lib/App/headtail.pm
Criterion Covered Total %
statement 6 18 33.3
branch 0 8 0.0
condition n/a
subroutine 2 3 66.6
pod 0 1 0.0
total 8 30 26.6


line stmt bran cond sub pod time code
1             package App::headtail;
2              
3 1     1   279804 use strict;
  1         2  
  1         41  
4 1     1   5 use warnings;
  1         1  
  1         348  
5              
6             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7             our $DATE = '2023-12-27'; # DATE
8             our $DIST = 'App-headtail'; # DIST
9             our $VERSION = '0.001'; # VERSION
10              
11             sub run {
12 0     0 0   my %opts = @_;
13              
14 0 0         if (defined $opts{lines}) {
15 0           my (@first, @last);
16              
17 0           while (<>) {
18 0 0         push @first, $_ unless @first >= $opts{lines};
19 0 0         push @last , $_; shift @last if @last > $opts{lines};
  0            
20             }
21              
22 0 0         if ($. < @first + @last) {
23 0           splice @last, 0, (@first + @last) - $.;
24             }
25              
26 0           print for @first;
27 0           print for @last;
28              
29             } else {
30 0           die;
31             }
32             }
33              
34              
35             1;
36             # ABSTRACT: head+tail
37              
38             __END__