blib/lib/Sort/Key/SortKey.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Sort::Key::SortKey;
2  
3 1 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use Module::Load::Util;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Sort::Key ();
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 my $sortkey = shift;
41 my $is_numeric = $f =~ /^(n|rn|i|ri|u|ru)/;
42 my $ns_prefixes = $is_numeric ? ["SortKey::Num", "SortKey"] : ["SortKey"];
43 my ($mod, $args) = Module::Load::Util::_normalize_module_with_optional_args($sortkey);
44 $mod = Module::Load::Util::_load_module({ns_prefixes=>$ns_prefixes}, $mod);
45 my $keygen = &{"$mod\::gen_keygen"}(@$args);
46 &{"Sort::Key::$f"}(sub { $keygen->($_) }, @_);
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__
↑ Summary