| 1 | package Sort::Sub::by_several; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||
| 4 | 2 | our $DATE = '2019-12-17'; # DATE | |||||||||||||
| 5 | 2 | our $DIST = 'Sort-Sub-by_several'; # DIST | |||||||||||||
| 6 | 2 | our $VERSION = '0.001'; # VERSION | |||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use 5.010001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 one or more sorters', | ||||||||||||||
| 16 | args => { | ||||||||||||||
| 17 | first => {schema=>'sortsub::spec*', req=>1, pos=>0}, | ||||||||||||||
| 18 | second => {schema=>'sortsub::spec*', req=>0, pos=>1}, | ||||||||||||||
| 19 | third => {schema=>'sortsub::spec*', req=>0, pos=>2}, | ||||||||||||||
| 20 | fourth => {schema=>'sortsub::spec*', req=>0, pos=>3}, | ||||||||||||||
| 21 | fifth => {schema=>'sortsub::spec*', req=>0, pos=>4}, | ||||||||||||||
| 22 | }, | ||||||||||||||
| 23 | args_rels => { | ||||||||||||||
| 24 | 'dep_any&' => [ | ||||||||||||||
| 25 | [second => ['first']], | ||||||||||||||
| 26 | [third => ['second']], | ||||||||||||||
| 27 | [fourth => ['third']], | ||||||||||||||
| 28 | [fifth => ['fourth']], | ||||||||||||||
| 29 | ], | ||||||||||||||
| 30 | }, | ||||||||||||||
| 31 | }; | ||||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 4 | ▶ | sub gen_sorter { | ||||||||||||
|
Subroutine
gen_sorter: called CC=6 SCAR=22.4
Pod
undocumented
| |||||||||||||||
| 35 | 4 | require Sort::Sub; | |||||||||||||
| 36 | 4 | my ($is_reverse, $is_ci, $args) = @_; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 4 | ▶ | my $sorter1 = defined $args->{first} ? Sort::Sub::get_sorter($args->{first} ) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 4 | ▶ | my $sorter2 = defined $args->{second} ? Sort::Sub::get_sorter($args->{second}) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 4 | ▶ | my $sorter3 = defined $args->{third} ? Sort::Sub::get_sorter($args->{third} ) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 4 | ▶ | my $sorter4 = defined $args->{fourth} ? Sort::Sub::get_sorter($args->{fourth}) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 4 | ▶ | my $sorter5 = defined $args->{fifth} ? Sort::Sub::get_sorter($args->{fifth} ) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | 92 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=34.8
| |||||||||||||||
| 45 | 2 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 46 | |||||||||||||||
| 47 | 92 | my $caller = caller(); | |||||||||||||
| 48 | 0 | ▶ | my $a = @_ ? $_[0] : ${"$caller\::a"}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 0 | ▶ | my $b = @_ ? $_[1] : ${"$caller\::b"}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | |||||||||||||||
| 51 | 92 | my $cmp; | |||||||||||||
| 52 | |||||||||||||||
| 53 | { | ||||||||||||||
| 54 | 92 | ▶ | $cmp = $sorter1->($a, $b); last if $cmp; last unless $sorter2; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 55 | 0 | ▶ | $cmp = $sorter2->($a, $b); last if $cmp; last unless $sorter3; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | 0 | ▶ | $cmp = $sorter3->($a, $b); last if $cmp; last unless $sorter4; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 57 | 0 | ▶ | $cmp = $sorter4->($a, $b); last if $cmp; last unless $sorter5; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 58 | 0 | $cmp = $sorter5->($a, $b); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 92 | ▶ | $is_reverse ? -1*$cmp : $cmp; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 4 | }; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 2 | 1; | |||||||||||||
| 66 | # ABSTRACT: Sort by one or more sorters | ||||||||||||||
| 67 | |||||||||||||||
| 68 | __END__ | ||||||||||||||