line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Unixish::subsort; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-01-06'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
465
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
345
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
1
|
|
|
|
|
19233
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
2903
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
10
|
|
|
|
|
|
|
#use Log::Any '$log'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
365
|
use Data::Unixish::Util qw(%common_args); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
239
|
|
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
|
|
|
|
|
|
|
reverse => { |
28
|
|
|
|
|
|
|
summary => 'Whether to reverse sort result', |
29
|
|
|
|
|
|
|
schema=>[bool => {default=>0}], |
30
|
|
|
|
|
|
|
cmdline_aliases => { r=>{} }, |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
ci => { |
33
|
|
|
|
|
|
|
summary => 'Whether to ignore case', |
34
|
|
|
|
|
|
|
schema=>[bool => {default=>0}], |
35
|
|
|
|
|
|
|
cmdline_aliases => { i=>{} }, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
tags => [qw/ordering/], |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
sub subsort { |
41
|
3
|
|
|
3
|
1
|
17
|
my %args = @_; |
42
|
3
|
|
|
|
|
8
|
my ($in, $out) = ($args{in}, $args{out}); |
43
|
3
|
50
|
|
|
|
9
|
my $routine = $args{routine} or return [400, "Please specify routine"]; |
44
|
3
|
|
|
|
|
5
|
my $reverse = $args{reverse}; |
45
|
3
|
|
|
|
|
4
|
my $ci = $args{ci}; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
6
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
48
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
175
|
|
49
|
3
|
|
|
|
|
5
|
my @buf; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# special case |
52
|
3
|
|
|
|
|
26
|
while (my ($index, $item) = each @$in) { |
53
|
9
|
|
|
|
|
25
|
push @buf, $item; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
444
|
require "Sort/Sub/$routine.pm"; |
57
|
3
|
|
|
|
|
276
|
my $gen_sorter = \&{"Sort::Sub::$routine\::gen_sorter"}; |
|
3
|
|
|
|
|
15
|
|
58
|
3
|
|
|
|
|
10
|
my $sorter = $gen_sorter->($reverse, $ci); |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
3987
|
@buf = sort {$sorter->($a, $b)} @buf; |
|
9
|
|
|
|
|
502
|
|
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
201
|
push @$out, $_ for @buf; |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
31
|
[200, "OK"]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
# ABSTRACT: Sort items using Sort::Sub routine |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |