File Coverage

lib/Perlmazing/Perlmazing/Precompile/sort_by_key.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 32     32   281 no warnings;
  32         76  
  32         6628  
3 32     32   3869 eval 'sub test_prototype (+) { 1 }; test_prototype(1);';
4 32         343 undef *test_prototype;
5 32 50       166 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 32     0   2358 eval 'sub main (+) { main_code(@_) }';
  0            
14 32 50       993 die $@ if $@;
15             }
16             }
17              
18 32     32   232 use Perlmazing qw(isa_hash void_context isa_array numeric list_context scalar_context);
  32         81  
  32         222  
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->{key} eq lc $b->{key}) {
  0            
38 0           numeric ($a->{key}, $b->{key});
39             } else {
40 0           numeric (lc $a->{key}, lc $b->{key});
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;