File Coverage

lib/Perlmazing/Perlmazing/Precompile/sort_by_value.pm
Criterion Covered Total %
statement 11 37 29.7
branch 2 20 10.0
condition n/a
subroutine 3 5 60.0
pod n/a
total 16 62 25.8


line stmt bran cond sub pod time code
1             BEGIN {
2 31     31   306 no warnings;
  31         95  
  31         6335  
3 31     31   3802 eval 'sub test_prototype (+) { 1 }; test_prototype(1);';
4 31         353 undef *test_prototype;
5 31 50       156 if (my $e = $@) {
6 0 0       0 if ($e =~ /Malformed prototype/) {
7 0         0 eval 'sub main (;\[@%]) { main_code(@_) }';
8 0 0       0 die $@ if $@;
9             } else {
10 0         0 die $e;
11             }
12             } else {
13 31     0   2474 eval 'sub main (+) { main_code(@_) }';
  0            
14 31 50       836 die $@ if $@;
15             }
16             }
17            
18 31     31   213 use Perlmazing;
  31         70  
  31         186  
19            
20             sub main_code {
21 0     0     my $list = $_[0];
22 0 0         if (isa_hash $list) {
    0          
23 0 0         if (void_context()) {
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) {
34 0           push @temp, {key => $list->[$i], value => $list->[$i + 1]};
35             }
36 0           @temp = map {$_->{key}, $_->{value}} sort {
37 0 0         if (lc $a->{value} eq lc $b->{value}) {
  0            
38 0           numeric ($a->{value}, $b->{value});
39             } else {
40 0           numeric (lc $a->{value}, lc $b->{value});
41             }
42             } @temp;
43 0 0         if (list_context()) {
    0          
44 0           @temp;
45             } elsif (scalar_context()) {
46 0           \@temp;
47             } else {
48 0           @{$_[0]} = @temp;
  0            
49             }
50             }
51            
52             1;