Script dies if a module that does not exist is used during sorting () - 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);

Conclusion:

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 checked, and it is definitely inside the subroutine. This does not seem to be related to 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
}

This seems to be a bug in PERL more than anything. Any ideas? More interested in why this happens than in a workaround - this only happens if the module does not exist.

+5
source share
1 answer

It seems like this is actually a bug in Perl. See this thread on the Perl Porters list.

+3
source

All Articles