File Coverage

blib/lib/Perinci/Sub/Util/Sort.pm
Criterion Covered Total %
statement 11 14 78.5
branch 0 2 0.0
condition 0 4 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 16 26 61.5


line stmt bran cond sub pod time code
1             package Perinci::Sub::Util::Sort;
2              
3 1     1   418834 use 5.010;
  1         5  
4 1     1   7 use strict;
  1         2  
  1         34  
5 1     1   7 use warnings;
  1         1  
  1         79  
6              
7 1     1   7 use Exporter qw(import);
  1         2  
  1         237  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2023-10-28'; # DATE
11             our $DIST = 'Perinci-Sub-Util'; # DIST
12             our $VERSION = '0.472'; # VERSION
13              
14             our @EXPORT_OK = qw(
15             sort_args
16             );
17              
18             our %SPEC;
19              
20             sub sort_args {
21 0     0 1   my $args = shift;
22             sort {
23 0 0 0       (($args->{$a}{pos} // 9999) <=> ($args->{$b}{pos} // 9999)) ||
  0   0        
24             $a cmp $b
25             } keys %$args;
26             }
27              
28             1;
29             # ABSTRACT: Sort routines
30              
31             __END__
32              
33             =pod
34              
35             =encoding UTF-8
36              
37             =head1 NAME
38              
39             Perinci::Sub::Util::Sort - Sort routines
40              
41             =head1 VERSION
42              
43             This document describes version 0.472 of Perinci::Sub::Util::Sort (from Perl distribution Perinci-Sub-Util), released on 2023-10-28.
44              
45             =head1 SYNOPSIS
46              
47             use Perinci::Sub::Util::Sort qw(sort_args);
48              
49             my $meta = {
50             v => 1.1,
51             args => {
52             a1 => { pos=>0 },
53             a2 => { pos=>1 },
54             opt1 => {},
55             opt2 => {},
56             },
57             };
58             my @args = sort_args($meta->{args}); # ('a1','a2','opt1','opt2')
59              
60             =head1 FUNCTIONS
61              
62             =head2 sort_args(\%args) => LIST
63              
64             Sort argument in args property by pos, then by name.
65              
66             =head1 HOMEPAGE
67              
68             Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Sub-Util>.
69              
70             =head1 SOURCE
71              
72             Source repository is at L<https://github.com/perlancar/perl-Perinci-Sub-Util>.
73              
74             =head1 AUTHOR
75              
76             perlancar <perlancar@cpan.org>
77              
78             =head1 CONTRIBUTING
79              
80              
81             To contribute, you can send patches by email/via RT, or send pull requests on
82             GitHub.
83              
84             Most of the time, you don't need to build the distribution yourself. You can
85             simply modify the code, then test via:
86              
87             % prove -l
88              
89             If you want to build the distribution (e.g. to try to install it locally on your
90             system), you can install L<Dist::Zilla>,
91             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
92             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
93             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
94             that are considered a bug and can be reported to me.
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2023, 2020, 2017, 2016, 2015, 2014 by perlancar <perlancar@cpan.org>.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =head1 BUGS
104              
105             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Util>
106              
107             When submitting a bug or request, please include a test-file or a
108             patch to an existing test-file that illustrates the bug or desired
109             feature.
110              
111             =cut