File Coverage

blib/lib/Sorter/file_by_size.pm
Criterion Covered Total %
statement 8 20 40.0
branch 0 4 0.0
condition 0 2 0.0
subroutine 3 6 50.0
pod 0 2 0.0
total 11 34 32.3


line stmt bran cond sub pod time code
1             package Sorter::file_by_size;
2              
3 1     1   425015 use 5.010001;
  1         5  
4 1     1   6 use strict;
  1         3  
  1         28  
5 1     1   6 use warnings;
  1         1  
  1         353  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-11-10'; # DATE
9             our $DIST = 'Sorter-file_by_size'; # DIST
10             our $VERSION = '0.001'; # VERSION
11              
12             sub meta {
13             return +{
14 0     0 0   v => 1,
15             summary => 'Sort files by size',
16             args => {
17             follow_symlink => {schema=>'bool*', default=>1},
18             reverse => {schema => 'bool*'},
19             #ci => {schema => 'bool*'},
20             },
21             };
22             }
23              
24             sub gen_sorter {
25 0     0 0   my %args = @_;
26              
27 0   0       my $follow_symlink = $args{follow_symlink} // 1;
28 0           my $reverse = $args{reverse};
29              
30             sub {
31 0     0     my @items = @_;
32 0 0         my @sizes = map { my @st = $follow_symlink ? stat($_) : lstat($_); $st[7] } @items;
  0            
  0            
33              
34 0           map { $items[$_] } sort {
35 0 0         $reverse ? $sizes[$b] <=> $sizes[$a] : $sizes[$a] <=> $sizes[$b]
  0            
36             } 0 .. $#items;
37 0           };
38             }
39              
40             1;
41             # ABSTRACT:
42              
43             __END__