| 1 | package Data::Unixish::subsort; | ||||||||||||
| 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 syntax 'each_on_array'; # to support perl < 5.12 | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | #use Log::Any '$log'; | ||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use Data::Unixish::Util qw(%common_args); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||
| 12 | 2 | our $DATE = '2025-02-24'; # DATE | |||||||||||
| 13 | 2 | our $DIST = 'Data-Unixish'; # DIST | |||||||||||
| 14 | 2 | our $VERSION = '1.574'; # VERSION | |||||||||||
| 15 | |||||||||||||
| 16 | 2 | our %SPEC; | |||||||||||
| 17 | |||||||||||||
| 18 | $SPEC{subsort} = { | ||||||||||||
| 19 | 2 | v => 1.1, | |||||||||||
| 20 | summary => 'Sort items using Sort::Sub routine', | ||||||||||||
| 21 | args => { | ||||||||||||
| 22 | %common_args, | ||||||||||||
| 23 | routine => { | ||||||||||||
| 24 | summary => 'Sort::Sub routine name', | ||||||||||||
| 25 | schema=>['str*', match=>qr/\A\w+\z/], | ||||||||||||
| 26 | req => 1, | ||||||||||||
| 27 | pos => 0, | ||||||||||||
| 28 | }, | ||||||||||||
| 29 | routine_args => { | ||||||||||||
| 30 | summary => 'Pass arguments for Sort::Sub routine', | ||||||||||||
| 31 | schema=>['hash*', of=>'str*'], | ||||||||||||
| 32 | cmdline_aliases => {a=>{}}, | ||||||||||||
| 33 | }, | ||||||||||||
| 34 | reverse => { | ||||||||||||
| 35 | summary => 'Whether to reverse sort result', | ||||||||||||
| 36 | schema=>[bool => {default=>0}], | ||||||||||||
| 37 | cmdline_aliases => { r=>{} }, | ||||||||||||
| 38 | }, | ||||||||||||
| 39 | ci => { | ||||||||||||
| 40 | summary => 'Whether to ignore case', | ||||||||||||
| 41 | schema=>[bool => {default=>0}], | ||||||||||||
| 42 | cmdline_aliases => { i=>{} }, | ||||||||||||
| 43 | }, | ||||||||||||
| 44 | }, | ||||||||||||
| 45 | tags => [qw/ordering/], | ||||||||||||
| 46 | }; | ||||||||||||
| 47 | 3 | ▶ | sub subsort { | ||||||||||
|
Subroutine
subsort: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 48 | 3 | my %args = @_; | |||||||||||
| 49 | 3 | my ($in, $out) = ($args{in}, $args{out}); | |||||||||||
| 50 | 3 | ▶ | my $routine = $args{routine} or return [400, "Please specify routine"]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 3 | ▶ | my $routine_args = $args{routine_args} // {}; | ||||||||||
|
Condition50%1/2
$args{"routine_args"} // {}
MC/DC0%0/1
$args{"routine_args"} // {}
$args{"routine_args"}
Truth table50%1/2
A
A= $args{"routine_args"}
| |||||||||||||
| 52 | 3 | my $reverse = $args{reverse}; | |||||||||||
| 53 | 3 | my $ci = $args{ci}; | |||||||||||
| 54 | |||||||||||||
| 55 | 2 | ▶ | no warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | 3 | my @buf; | |||||||||||
| 58 | |||||||||||||
| 59 | # special case | ||||||||||||
| 60 | 3 | ▶ | while (my ($index, $item) = each @$in) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 9 | push @buf, $item; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 3 | require "Sort/Sub/$routine.pm"; ## no critic: Modules::RequireBarewordIncludes | |||||||||||
| 65 | 3 | my $gen_sorter = \&{"Sort::Sub::$routine\::gen_sorter"}; | |||||||||||
| 66 | 3 | my $sorter = $gen_sorter->($reverse, $ci, $routine_args); | |||||||||||
| 67 | |||||||||||||
| 68 | 3 | @buf = sort {$sorter->($a, $b)} @buf; | |||||||||||
| 69 | |||||||||||||
| 70 | 3 | push @$out, $_ for @buf; | |||||||||||
| 71 | |||||||||||||
| 72 | 3 | [200, "OK"]; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 2 | 1; | |||||||||||
| 76 | # ABSTRACT: Sort items using Sort::Sub routine | ||||||||||||
| 77 | |||||||||||||
| 78 | __END__ | ||||||||||||