Sort/Sub/by_ascii_then_num.pm

filter: Statementstmt 91.1% 31 / 34 Branchbran 85.7% 12 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 85.9% 49 / 57 CC 8 SCAR 16.4
CC
8
Cov
90%
__ANON__
8.1
meta
2.0
gen_sorter
1.0
CRAP 5.2
« Sort/Sub/by_count.pm ↑ Summary Sort/Sub/by_num_then_ascii.pm »
1 package Sort::Sub::by_ascii_then_num;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2024-07-17'; # DATE
9 2 our $DIST = 'Sort-Sub'; # DIST
10 2 our $VERSION = '0.121'; # VERSION
11  
12 0 ▶sub meta {
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
13 return {
14 0 v => 1,
15 summary => 'Sort non-numbers (sorted asciibetically) before numbers (sorted numerically)',
16 };
17 }
18  
19 3 ▶sub gen_sorter {
Subroutine gen_sorter: called CC=1 SCAR=0.0
Pod undocumented
20 3 my ($is_reverse, $is_ci) = @_;
21  
22 3 my $re_is_num = qr/\A
23 [+-]?
24 (?:\d+|\d*(?:\.\d*)?)
25 (?:[Ee][+-]?\d+)?
26 \z/x;
27  
28 34 ▶ sub {
Subroutine __ANON__: called CC=8 SCAR=21.0
29 2 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 34 my $caller = caller();
32 0 ▶ my $a = @_ ? $_[0] : ${"$caller\::a"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 34 0 34
33 0 ▶ my $b = @_ ? $_[1] : ${"$caller\::b"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 34 0 34
34  
35 34 my $cmp = 0;
36 34 ▶ if ($a =~ $re_is_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /$re_is_num/) { } 16 18 34
37 16 ▶ if ($b =~ $re_is_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ /$re_is_num/) { } 7 9 16
38 7 $cmp = $a <=> $b;
39 } else {
40 9 $cmp = 1;
41 }
42 } else {
43 18 ▶ if ($b =~ $re_is_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ /$re_is_num/) { } 3 15 18
44 3 $cmp = -1;
45 } else {
46 15 ▶ $cmp = $is_ci ?
Branch: 1 branch
BranchTrueFalseTotal
$is_ci ? : 9 6 15
47 lc($a) cmp lc($b) : $a cmp $b;
48 }
49 }
50 34 ▶ $is_reverse ? -1*$cmp : $cmp;
Branch: 1 branch
BranchTrueFalseTotal
$is_reverse ? : 12 22 34
51 3 };
52 }
53  
54 2 1;
55 # ABSTRACT: Sort non-numbers (sorted asciibetically) before numbers (sorted numerically)
56  
57 __END__
« Sort/Sub/by_count.pm ↑ Summary Sort/Sub/by_num_then_ascii.pm »