Sort/Sub/by_perl_op.pm

filter: Statementstmt 90.3% 28 / 31 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 80.0% 40 / 50 CC 6 SCAR 9.9
CC
6
Cov
83%
__ANON__
4.2
gen_sorter
3.1
meta
2.0
CRAP 2.7
« Test/Sort/Sub.pm ↑ Summary Sort/Sub/by_length.pm »
1 package Sort::Sub::by_perl_op;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2024-07-17'; # DATE
9 2 our $DIST = 'Sort-Sub'; # DIST
10 2 our $VERSION = '0.121'; # VERSION
11  
12 0 ▶sub meta {
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
13 return {
14 0 v => 1,
15 summary => 'Sort by Perl operator',
16 args => {
17 op => {
18 schema => ['str*', in=>['cmp', '<=>']],
19 req => 1,
20 },
21 },
22 };
23 }
24 3 ▶sub gen_sorter {
Subroutine gen_sorter: called CC=3 SCAR=11.3
Pod undocumented
25 3 my ($is_reverse, $is_ci, $args) = @_;
26  
27 3 my $op = $args->{op};
28 3 ▶ die "Please supply sorter argument 'op'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op 0 3 3
29 unless defined $op;
30  
31 3 my $code_str = "sub { \$_[0] $op \$_[1] }";
32 3 my $code_cmp = eval $code_str; ## no critic: BuiltinFunctions::ProhibitStringyEval
33 3 ▶ die "Can't compile $code_str: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
34  
35 8 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
36 2 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 8 my $caller = caller();
39 0 ▶ my $a = @_ ? $_[0] : ${"$caller\::a"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 0 8
40 0 ▶ my $b = @_ ? $_[1] : ${"$caller\::b"};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 0 8
41  
42 8 my $cmp = $code_cmp->($a, $b);
43 8 ▶ $is_reverse ? -1*$cmp : $cmp;
Branch: 1 branch
BranchTrueFalseTotal
$is_reverse ? : 6 2 8
44 3 };
45 }
46  
47 2 1;
48 # ABSTRACT: Sort by Perl operator
49  
50 __END__
« Test/Sort/Sub.pm ↑ Summary Sort/Sub/by_length.pm »