lib/Perlmazing/Perlmazing/Precompile/sort_by_key.pm

filter: Statementstmt 31.5% 12 / 38 Branchbran 9.0% 2 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 27.2% 18 / 66 CC 12 SCAR 36.0
CC
12
Cov
23%
main_code
72.0
BEGIN
8.1
main
1.1
CRAP 36.5
« lib/Perlmazing/Engine/Exporter.pm ↑ Summary lib/Perlmazing/Perlmazing/Precompile/sort_by_value.pm »
1 30 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=20.9
2 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 30 ▶ eval 'sub test_prototype (+) { 1 }; test_prototype(1);';
Subroutine test_prototype: called CC=1 SCAR=0.0
4 30 undef *test_prototype;
5 30 ▶ if (my $e = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) { } 0 30 30
6 0 ▶ if ($e =~ /Malformed prototype/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /Malformed prototype/u) { } 0 0 0
7 0 eval 'sub main (;\[@%]) { main_code(@_) }';
8 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
9 } else {
10 0 die $e;
11 }
12 } else {
13 0 ▶ eval 'sub main (+) { main_code(@_) }';
Subroutine main: not called CC=1 SCAR=1.2
14 30 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 30 30
15 }
16 }
17  
18 30 ▶use Perlmazing qw(isa_hash void_context isa_array numeric list_context scalar_context);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶sub main_code {
Subroutine main_code: not called CC=8 SCAR=42.8
21 0 my $list = $_[0];
22 0 ▶ if (isa_hash $list) {
Branch: 2 branches
BranchTrueFalseTotal
if (&isa_hash($list)) { } 0 0 0
elsif (not &isa_array($list)) { } 0 0 0
23 0 ▶ if (void_context()) {
Branch: 1 branch
BranchTrueFalseTotal
if (&void_context()) 0 0 0
24 0 my @call = caller(0);
25 0 warn "Useless call to sort_by_key for a hash in void context (keys won't remain sorted in a hash) at $call[1] line $call[2]\n";
26 0 return;
27 }
28 0 $list = [%$list];
29 } elsif (not isa_array $list) {
30 0 return $_[0];
31 }
32 0 my @temp;
33 0 ▶ for (my $i = 0; $i < @$list; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$list) 0 0 0
34 0 push @temp, {key => $list->[$i], value => $list->[$i + 1]};
35 }
36 0 @temp = map {$_->{key}, $_->{value}} sort {
37 0 ▶ if (lc $a->{key} eq lc $b->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $Perlmazing::Perlmazing::sort_by_key::a->{'key'} eq lc $Perlmazing::Perlmazing::sort_by_key::b->{'key'}) { } 0 0 0
38 0 numeric ($a->{key}, $b->{key});
39 } else {
40 0 numeric (lc $a->{key}, lc $b->{key});
41 }
42 } @temp;
43 0 ▶ if (list_context()) {
Branch: 2 branches
BranchTrueFalseTotal
if (&list_context()) { } 0 0 0
elsif (&scalar_context()) { } 0 0 0
44 0 @temp;
45 } elsif (scalar_context()) {
46 0 \@temp;
47 } else {
48 0 @{$_[0]} = @temp;
49 }
50 }
51  
52 1;
« lib/Perlmazing/Engine/Exporter.pm ↑ Summary lib/Perlmazing/Perlmazing/Precompile/sort_by_value.pm »