| 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
| |||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $b = @_ ? $_[1] : ${"$caller\::b"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | my $num_b; @nums = $b =~ /(\d+)/g; $num_b = $nums[-1] if @nums; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | if (defined $num_a && defined $num_b) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
defined $num_a and defined $num_b
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
| |||||||||||||||||||||||||||||||||||||
| 37 | 6 | $cmp = $num_a <=> $num_b; | |||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | last if $cmp; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 39 | ▶ | } elsif (defined $num_a && !defined $num_b) { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $num_a and not defined $num_b
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
| |||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||
| 43 | 2 | $cmp = 1; | |||||||||||||||||||||||||||||||||||
| 44 | 2 | last; | |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($is_ci) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||