开发者

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

use DateTime::Time开发者_运维问答Zone::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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜