« blib/lib/App/RecordStream/Operation/multiplex/BaseClumperCallback.pm
↑ Summary
blib/lib/App/RecordStream/Clumper/KeyLRU.pm »
| 1 | package App::RecordStream::Operation::sort; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | our $VERSION = "4.0.23"; | |||||||||
| 4 | |||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 7 | ▶ | use base qw(App::RecordStream::Accumulator App::RecordStream::Operation); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | sub init { | ||||||||||
| 11 | 8 | ▶ | my $this = shift; | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | 8 | my $args = shift; | |||||||||
| 13 | |||||||||||
| 14 | 8 | my @keys; | |||||||||
| 15 | my $reverse; | ||||||||||
| 16 | |||||||||||
| 17 | my $spec = { | ||||||||||
| 18 | 7 | ▶ | "key|k=s" => sub { push @keys, split(/,/, $_[1]); }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 8 | "reverse|r" => \$reverse, | |||||||||
| 20 | }; | ||||||||||
| 21 | |||||||||||
| 22 | 8 | $this->parse_options($args, $spec); | |||||||||
| 23 | |||||||||||
| 24 | 7 | $this->{'KEYS'} = \@keys; | |||||||||
| 25 | 7 | $this->{'REVERSE'} = $reverse; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub stream_done { | ||||||||||
| 29 | 5 | ▶ | my $this = shift; | ||||||||
|
Subroutine
stream_done: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 30 | |||||||||||
| 31 | 5 | my @records = App::RecordStream::Record::sort($this->get_records(), @{$this->{'KEYS'}}); | |||||||||
| 32 | |||||||||||
| 33 | 5 | ▶ | if ( $this->{'REVERSE'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | @records = reverse @records; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 5 | foreach my $record (@records) { | |||||||||
| 38 | 37 | $this->push_record($record); | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub add_help_types { | ||||||||||
| 43 | 8 | ▶ | my $this = shift; | ||||||||
|
Subroutine
add_help_types: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | 8 | $this->use_help_type('keyspecs'); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub usage { | ||||||||||
| 48 | 1 | ▶ | my $this = shift; | ||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | 1 | my $options = [ | |||||||||
| 51 | ['key <keyspec>', "May be comma separated, May be specified multiple times. Each keyspec is a name or a name=sortType. The name should be a field name to sort on. The sort type should be either lexical or numeric. Default sort type is lexical (can also use nat, lex, n, and l). Additionallly, the sort type may be prefixed with '-' to indicate a decreasing sort order. Additionally, the sort type may be postfixed with '*' to sort the special value 'ALL' to the end (useful for the output of recs-collate --cube). See perldoc for App::RecordStream::Record for more on sort specs. May be a key spec, see '--help-keyspecs' for more. Cannot be a keygroup."], | ||||||||||
| 52 | ['reverse', 'Reverses the sort order'], | ||||||||||
| 53 | ]; | ||||||||||
| 54 | |||||||||||
| 55 | 1 | my $args_string = $this->options_string($options); | |||||||||
| 56 | |||||||||||
| 57 | 1 | return <<USAGE; | |||||||||
| 58 | Usage: recs-sort <args> [<files>] | ||||||||||
| 59 | __FORMAT_TEXT__ | ||||||||||
| 60 | Sorts records from input or from <files>. You may sort on a list of keys, | ||||||||||
| 61 | each key sorted lexically (alpha order) or numerically | ||||||||||
| 62 | __FORMAT_TEXT__ | ||||||||||
| 63 | |||||||||||
| 64 | $args_string | ||||||||||
| 65 | |||||||||||
| 66 | Examples: | ||||||||||
| 67 | Sort on the id field, a numeric | ||||||||||
| 68 | recs-sort --key id=numeric | ||||||||||
| 69 | Sort on age, then name | ||||||||||
| 70 | recs-sort --key age=numeric,name | ||||||||||
| 71 | Sort on decreasing size, name | ||||||||||
| 72 | recs-sort --key size=-numeric --key name | ||||||||||
| 73 | USAGE | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 7 | 1; | |||||||||