line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sort::Sub::asciibetically; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-05-25'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Sort-Sub'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.120'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
15
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
10
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
0
|
0
|
v => 1, |
15
|
|
|
|
|
|
|
summary => 'Sort ascibetically (string-wise)', |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub gen_sorter { |
20
|
3
|
|
|
3
|
0
|
6
|
my ($is_reverse, $is_ci) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub { |
23
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
24
|
|
|
|
|
|
|
|
25
|
34
|
|
|
34
|
|
39
|
my $caller = caller(); |
26
|
34
|
50
|
|
|
|
40
|
my $a = @_ ? $_[0] : ${"$caller\::a"}; |
|
0
|
|
|
|
|
0
|
|
27
|
34
|
50
|
|
|
|
51
|
my $b = @_ ? $_[1] : ${"$caller\::b"}; |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
|
29
|
34
|
100
|
|
|
|
47
|
my $cmp = $is_ci ? lc($a) cmp lc($b) : $a cmp $b; |
30
|
34
|
100
|
|
|
|
59
|
$is_reverse ? -1*$cmp : $cmp; |
31
|
3
|
|
|
|
|
12
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
# ABSTRACT: Sort ascibetically (string-wise) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding UTF-8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Sort::Sub::asciibetically - Sort ascibetically (string-wise) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 VERSION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This document describes version 0.120 of Sort::Sub::asciibetically (from Perl distribution Sort-Sub), released on 2020-05-25. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Generate sorter (accessed as variable) via L<Sort::Sub> import: |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Sort::Sub '$asciibetically'; # use '$asciibetically<i>' for case-insensitive sorting, '$asciibetically<r>' for reverse sorting |
56
|
|
|
|
|
|
|
my @sorted = sort $asciibetically ('item', ...); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Generate sorter (accessed as subroutine): |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Sort::Sub 'asciibetically<ir>'; |
61
|
|
|
|
|
|
|
my @sorted = sort {asciibetically} ('item', ...); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Generate directly without Sort::Sub: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use Sort::Sub::asciibetically; |
66
|
|
|
|
|
|
|
my $sorter = Sort::Sub::asciibetically::gen_sorter( |
67
|
|
|
|
|
|
|
ci => 1, # default 0, set 1 to sort case-insensitively |
68
|
|
|
|
|
|
|
reverse => 1, # default 0, set 1 to sort in reverse order |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
my @sorted = sort $sorter ('item', ...); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Use in shell/CLI with L<sortsub> (from L<App::sortsub>): |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
% some-cmd | sortsub asciibetically |
75
|
|
|
|
|
|
|
% some-cmd | sortsub asciibetically --ignore-case -r |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is equivalent to Perl's: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub { $a cmp $b } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=for Pod::Coverage ^(gen_sorter|meta)$ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 HOMEPAGE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Sort-Sub>. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SOURCE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Sort-Sub>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sort-Sub> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
98
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
99
|
|
|
|
|
|
|
feature. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<Sort::Sub> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is copyright (c) 2020, 2019, 2018, 2016, 2015 by perlancar@cpan.org. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
114
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |