Sort/Sub/by_last_num_in_text.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 74.7% 65 / 87 CC 14 SCAR 25.5
CC
14
Cov
78%
__ANON__
17.8
meta
2.0
gen_sorter
1.0
CRAP 12.8
« Sort/Sub/by_num_in_text.pm ↑ Summary Sort/Sub.pm »
1 package Sort::Sub::by_last_num_in_text;
2  
3 2 ▶use 5.010001;
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 by last number found in text or (if no number is found) ascibetically',
16 };
17 }
18  
19 1 ▶sub gen_sorter {
Subroutine gen_sorter: called CC=1 SCAR=0.2
Pod undocumented
20 1 my ($is_reverse, $is_ci) = @_;
21  
22 9 ▶ sub {
Subroutine __ANON__: called CC=14 SCAR=28.8
23 2 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 9 my $caller = caller();
26 0 ▶ my $a = @_ ? $_[0] : ${"$caller\::a"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 9 0 9
27 0 ▶ my $b = @_ ? $_[1] : ${"$caller\::b"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 9 0 9
28  
29 9 my $cmp;
30  
31 my @nums;
32 9 ▶ my $num_a; @nums = $a =~ /(\d+)/g; $num_a = $nums[-1] if @nums;
Branch: 1 branch
BranchTrueFalseTotal
if @nums 7 2 9
33 9 ▶ my $num_b; @nums = $b =~ /(\d+)/g; $num_b = $nums[-1] if @nums;
Branch: 1 branch
BranchTrueFalseTotal
if @nums 8 1 9
34  
35 {
36 9 ▶ if (defined $num_a && defined $num_b) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $num_a and defined $num_b) { } 6 3 9
elsif (defined $num_a and not defined $num_b) { } 1 2 3
elsif (not defined $num_a and defined $num_b) { } 2 0 2
Condition100%3/3
defined $num_a and defined $num_b
!ll&&!rl&&r
216
MC/DC100%2/2
defined $num_a and defined $num_b
defined $num_a defined $num_b
Truth table100%3/3
A and B
A= defined $num_aB= defined $num_b
ABresult
0X0
100
111
37 6 $cmp = $num_a <=> $num_b;
38 6 ▶ last if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 6 0 6
39 ▶ } elsif (defined $num_a && !defined $num_b) {
Condition66%2/3
defined $num_a and not defined $num_b
!ll&&!rl&&r
201
MC/DC50%1/2
defined $num_a and not defined $num_b
defined $num_a not defined $num_b
Truth table66%2/3
A and not(B)
A= defined $num_aB= not defined $num_b
ABresult
0X0
100
111
40 1 $cmp = -1;
41 1 last;
42 ▶ } elsif (!defined $num_a && defined $num_b) {
Condition33%1/3
not defined $num_a and defined $num_b
!ll&&!rl&&r
002
MC/DC0%0/2
not defined $num_a and defined $num_b
not defined $num_a defined $num_b
Truth table33%1/3
not(A) and B
A= not defined $num_aB= defined $num_b
ABresult
0X0
100
111
43 2 $cmp = 1;
44 2 last;
45 }
46  
47 0 ▶ if ($is_ci) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ci) { } 0 0 0
48 0 $cmp = lc($a) cmp lc($b);
49 } else {
50 0 $cmp = $a cmp $b;
51 }
52 }
53  
54 9 ▶ $is_reverse ? -1*$cmp : $cmp;
Branch: 1 branch
BranchTrueFalseTotal
$is_reverse ? : 0 9 9
55 1 };
56 }
57  
58 2 1;
59 # ABSTRACT: Sort by last number found in text or (if no number is found) ascibetically
60  
61 __END__
« Sort/Sub/by_num_in_text.pm ↑ Summary Sort/Sub.pm »