From: Vincent Pit Date: Fri, 13 Mar 2015 15:08:19 +0000 (-0300) Subject: Guard against exceptions thrown by Module::Metadata X-Git-Tag: rt91248^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=a5f2d9b989d2afcdb4a7b0cc374439627a516656;p=perl%2Fmodules%2FAcme-CPANAuthors-You-re_using.git Guard against exceptions thrown by Module::Metadata This fixes RT #91248. --- diff --git a/MANIFEST b/MANIFEST index e8bd01d..42615e6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,3 +8,5 @@ lib/Acme/CPANAuthors/You/re_using.pm samples/list_authors t/00-load.t t/10-base.t +t/11-naughty-version.t +t/lib/Acme/CPANAuthors/You/re_using/TestNaughtyVersion.pm diff --git a/lib/Acme/CPANAuthors/You/re_using.pm b/lib/Acme/CPANAuthors/You/re_using.pm index 9fbe898..a2474bb 100644 --- a/lib/Acme/CPANAuthors/You/re_using.pm +++ b/lib/Acme/CPANAuthors/You/re_using.pm @@ -65,7 +65,10 @@ sub register { File::Find::find({ wanted => sub { return unless /\.pm$/; - my $mod = Module::Metadata->new_from_file($_); + my $mod = do { + local $@; + eval { Module::Metadata->new_from_file($_) } + }; return unless $mod; @modules{grep $_, $mod->packages_inside} = (); }, diff --git a/t/11-naughty-version.t b/t/11-naughty-version.t new file mode 100644 index 0000000..1cf4385 --- /dev/null +++ b/t/11-naughty-version.t @@ -0,0 +1,31 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 2; + +use lib 't/lib'; + +use Acme::CPANAuthors; + +local @INC = grep $_ ne '.', @INC; + +our $test_loaded; +local $test_loaded = 0; + +my $err = do { + local $SIG{__WARN__} = sub { + my $msg = join "\n", @_; + if ($msg =~ /cabbage/) { + die "$msg\n"; + } else { + diag $msg; + } + }; + eval { Acme::CPANAuthors->new("You're_using") }; + $@; +}; + +is $test_loaded, 1, 'naughty module was actually loaded'; +is $err, '', 'naughty module did not make us croak'; diff --git a/t/lib/Acme/CPANAuthors/You/re_using/TestNaughtyVersion.pm b/t/lib/Acme/CPANAuthors/You/re_using/TestNaughtyVersion.pm new file mode 100644 index 0000000..f99728c --- /dev/null +++ b/t/lib/Acme/CPANAuthors/You/re_using/TestNaughtyVersion.pm @@ -0,0 +1,10 @@ +package Acme::CPANAuthors::You::re_using::TestNaughtyVersion; + +my $zero; +if ($zero) { + +our $VERSION = do { $main::test_loaded = 1; die 'cabbage' }; + +} + +1;