Sort/Sub/by_num_in_text.pm

filter: Statementstmt 85.0% 34 / 40 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 73.8% 62 / 84 CC 14 SCAR 25.8
CC
14
Cov
77%
__ANON__
18.4
meta
2.0
gen_sorter
1.0
CRAP 13.3
↑ Summary Sort/Sub/by_last_num_in_text.pm »
1 package Sort::Sub::by_num_in_text;
2  
3 4 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 4 our $DATE = '2024-07-17'; # DATE
9 4 our $DIST = 'Sort-Sub'; # DIST
10 4 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 first number found in text or (if no number is found) ascibetically',
16 };
17 }
18 2 ▶sub gen_sorter {
Subroutine gen_sorter: called CC=1 SCAR=0.2
Pod undocumented
19 2 my ($is_reverse, $is_ci) = @_;
20  
21 18 ▶ sub {
Subroutine __ANON__: called CC=14 SCAR=29.1
22 4 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 18 my $caller = caller();
25 0 ▶ my $a = @_ ? $_[0] : ${"$caller\::a"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 18 0 18
26 0 ▶ my $b = @_ ? $_[1] : ${"$caller\::b"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 18 0 18
27  
28 18 my $cmp;
29  
30 18 ▶ my $num_a; $num_a = $1 if $a =~ /(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $a =~ /(\d+)/ 14 4 18
31 18 ▶ my $num_b; $num_b = $1 if $b =~ /(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $b =~ /(\d+)/ 16 2 18
32  
33 {
34 18 ▶ if (defined $num_a && defined $num_b) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $num_a and defined $num_b) { } 12 6 18
elsif (defined $num_a and not defined $num_b) { } 2 4 6
elsif (not defined $num_a and defined $num_b) { } 4 0 4
Condition100%3/3
defined $num_a and defined $num_b
!ll&&!rl&&r
4212
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
35 12 $cmp = $num_a <=> $num_b;
36 12 ▶ last if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 12 0 12
37 ▶ } elsif (defined $num_a && !defined $num_b) {
Condition66%2/3
defined $num_a and not defined $num_b
!ll&&!rl&&r
402
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
38 2 $cmp = -1;
39 2 last;
40 ▶ } elsif (!defined $num_a && defined $num_b) {
Condition33%1/3
not defined $num_a and defined $num_b
!ll&&!rl&&r
004
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
41 4 $cmp = 1;
42 4 last;
43 }
44  
45 0 ▶ if ($is_ci) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ci) { } 0 0 0
46 0 $cmp = lc($a) cmp lc($b);
47 } else {
48 0 $cmp = $a cmp $b;
49 }
50 }
51  
52 18 ▶ $is_reverse ? -1*$cmp : $cmp;
Branch: 1 branch
BranchTrueFalseTotal
$is_reverse ? : 0 18 18
53 2 };
54 }
55  
56 4 1;
57 # ABSTRACT: Sort by first number found in text or (if no number is found) ascibetically
58  
59 __END__
↑ Summary Sort/Sub/by_last_num_in_text.pm »