line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::subsort; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-10-26'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '1.572'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
451
|
use 5.010; |
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
8
|
1
|
|
|
1
|
|
343
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
19355
|
|
|
1
|
|
|
|
|
3
|
|
9
|
1
|
|
|
1
|
|
2850
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
10
|
|
|
|
|
|
|
#use Log::Any '$log'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
350
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
240
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %SPEC; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$SPEC{subsort} = { |
17
|
|
|
|
|
|
|
v => 1.1, |
18
|
|
|
|
|
|
|
summary => 'Sort items using Sort::Sub routine', |
19
|
|
|
|
|
|
|
args => { |
20
|
|
|
|
|
|
|
%common_args, |
21
|
|
|
|
|
|
|
routine => { |
22
|
|
|
|
|
|
|
summary => 'Sort::Sub routine name', |
23
|
|
|
|
|
|
|
schema=>['str*', match=>qr/\A\w+\z/], |
24
|
|
|
|
|
|
|
req => 1, |
25
|
|
|
|
|
|
|
pos => 0, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
routine_args => { |
28
|
|
|
|
|
|
|
summary => 'Pass arguments for Sort::Sub routine', |
29
|
|
|
|
|
|
|
schema=>['hash*', of=>'str*'], |
30
|
|
|
|
|
|
|
cmdline_aliases => {a=>{}}, |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
reverse => { |
33
|
|
|
|
|
|
|
summary => 'Whether to reverse sort result', |
34
|
|
|
|
|
|
|
schema=>[bool => {default=>0}], |
35
|
|
|
|
|
|
|
cmdline_aliases => { r=>{} }, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
ci => { |
38
|
|
|
|
|
|
|
summary => 'Whether to ignore case', |
39
|
|
|
|
|
|
|
schema=>[bool => {default=>0}], |
40
|
|
|
|
|
|
|
cmdline_aliases => { i=>{} }, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
tags => [qw/ordering/], |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
sub subsort { |
46
|
3
|
|
|
3
|
1
|
12
|
my %args = @_; |
47
|
3
|
|
|
|
|
5
|
my ($in, $out) = ($args{in}, $args{out}); |
48
|
3
|
50
|
|
|
|
8
|
my $routine = $args{routine} or return [400, "Please specify routine"]; |
49
|
3
|
|
50
|
|
|
12
|
my $routine_args = $args{routine_args} // {}; |
50
|
3
|
|
|
|
|
5
|
my $reverse = $args{reverse}; |
51
|
3
|
|
|
|
|
3
|
my $ci = $args{ci}; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
6
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
54
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
157
|
|
55
|
3
|
|
|
|
|
5
|
my @buf; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# special case |
58
|
3
|
|
|
|
|
11
|
while (my ($index, $item) = each @$in) { |
59
|
9
|
|
|
|
|
22
|
push @buf, $item; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
448
|
require "Sort/Sub/$routine.pm"; |
63
|
3
|
|
|
|
|
310
|
my $gen_sorter = \&{"Sort::Sub::$routine\::gen_sorter"}; |
|
3
|
|
|
|
|
9
|
|
64
|
3
|
|
|
|
|
8
|
my $sorter = $gen_sorter->($reverse, $ci, $routine_args); |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
4019
|
@buf = sort {$sorter->($a, $b)} @buf; |
|
9
|
|
|
|
|
458
|
|
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
238
|
push @$out, $_ for @buf; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
25
|
[200, "OK"]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
# ABSTRACT: Sort items using Sort::Sub routine |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |