File Coverage

blib/lib/Sort/Key/SortKey.pm
Criterion Covered Total %
statement 15 25 60.0
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod n/a
total 20 34 58.8


line stmt bran cond sub pod time code
1             package Sort::Key::SortKey;
2              
3 1     1   408174 use strict 'subs', 'vars';
  1         3  
  1         77  
4 1     1   7 use warnings;
  1         2  
  1         76  
5              
6 1     1   11 use Exporter qw(import);
  1         2  
  1         35  
7 1     1   730 use Module::Load::Util;
  1         3154  
  1         66  
8 1     1   712 use Sort::Key ();
  1         4395  
  1         543  
9              
10             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11             our $DATE = '2024-01-24'; # DATE
12             our $DIST = 'Sort-Key-SortKey'; # DIST
13             our $VERSION = '0.001'; # VERSION
14              
15             our @EXPORT_OK = @Sort::Key::EXPORT_OK;
16              
17             for my $f (qw/
18             nsort nsort_inplace
19             isort isort_inplace
20             usort usort_inplace
21             rsort rsort_inplace
22             rnsort rnsort_inplace
23             risort risort_inplace
24             rusort rusort_inplace
25             /) {
26             *{"$f"} = \&{"Sort::Key\::$f"};
27             }
28              
29             for my $f (qw/
30             keysort keysort_inplace
31             rkeysort rkeysort_inplace
32             nkeysort nkeysort_inplace
33             rnkeysort rnkeysort_inplace
34             ikeysort ikeysort_inplace
35             rikeysort rikeysort_inplace
36             ukeysort ukeysort_inplace
37             rukeysort rukeysort_inplace
38             /) {
39             *{"$f"} = sub {
40 0     0     my $sortkey = shift;
41 0           my $is_numeric = $f =~ /^(n|rn|i|ri|u|ru)/;
42 0 0         my $ns_prefixes = $is_numeric ? ["SortKey::Num", "SortKey"] : ["SortKey"];
43 0           my ($mod, $args) = Module::Load::Util::_normalize_module_with_optional_args($sortkey);
44 0           $mod = Module::Load::Util::_load_module({ns_prefixes=>$ns_prefixes}, $mod);
45 0           my $keygen = &{"$mod\::gen_keygen"}(@$args);
  0            
46 0     0     &{"Sort::Key::$f"}(sub { $keygen->($_) }, @_);
  0            
  0            
47             };
48             }
49              
50             for my $f (qw/
51             multikeysorter multikeysorter_inplace
52             /) {
53             # XXX currently we don't wrap
54             *{"$f"} = \&{"Sort::Key\::$f"};
55             }
56              
57             1;
58             # ABSTRACT: Thin wrapper for Sort::Key to easily use SortKey::*
59              
60             __END__