File Coverage

blib/lib/Sort/Sub/by_length.pm
Criterion Covered Total %
statement 18 21 85.7
branch 4 6 66.6
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 28 36 77.7


line stmt bran cond sub pod time code
1             package Sort::Sub::by_length;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-02-28'; # DATE
5             our $DIST = 'Sort-Sub'; # DIST
6             our $VERSION = '0.118'; # VERSION
7              
8 1     1   20 use 5.010;
  1         4  
9 1     1   6 use strict;
  1         1  
  1         21  
10 1     1   5 use warnings;
  1         1  
  1         83  
11              
12             sub meta {
13             return {
14 0     0 0 0 v => 1,
15             summary => 'Sort by length of string',
16             };
17             }
18             sub gen_sorter {
19 3     3 0 7 my ($is_reverse, $is_ci) = @_;
20              
21             sub {
22 1     1   7 no strict 'refs';
  1         2  
  1         155  
23              
24 8     8   14 my $caller = caller();
25 8 50       16 my $a = @_ ? $_[0] : ${"$caller\::a"};
  0         0  
26 8 50       13 my $b = @_ ? $_[1] : ${"$caller\::b"};
  0         0  
27              
28 8         13 my $cmp = length($a) <=> length($b);
29 8 100       28 $is_reverse ? -1*$cmp : $cmp;
30 3         20 };
31             }
32              
33             1;
34             # ABSTRACT: Sort by length of string
35              
36             __END__