Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script dies if a module that doesnt exist is used during sort() - DateTime::TimeZone::Local example

use DateTime::TimeZone::Local;
use Test::More tests => 1;

my @input = (1 .. 10 );
my (@output) = sort {
    DateTime::TimeZone::Local->TimeZone();
    $a cmp $b
} @input;

is_deeply(\@output, \@input);

Output:

1..1
Can't return outside a subroutine at /usr/local/share/perl/5.8.8/DateTime/TimeZone/Local.pm line 72.
# Looks like your test exited with 9 before it could output anything.

shell returned 9

I have checked and it definitely is inside a sub routine. It doesn't appear to be anything to do with the module used, this code also causes the same error:

my @output = sort {
    sub1();
} (1 .. 5);

sub sub1 {
    eval "use ModuleDoesntExist";
    return 1; # remove this and get a seg fault
}

Looks like it is a bug in perl more than anything. Any ideas? More interested in why this is happening than a workaround - it only occurs if the module doesn't exist.

like image 398
Darren Westall Avatar asked Oct 26 '22 02:10

Darren Westall


1 Answers

It looks as though it is actually a bug in Perl. See this thread on the Perl Porters list.

like image 63
Simon Whitaker Avatar answered Nov 15 '22 13:11

Simon Whitaker