]> git.vpit.fr Git - perl/modules/Acme-CPANAuthors-You-re_using.git/commitdiff
Guard against exceptions thrown by Module::Metadata rt91248
authorVincent Pit <vince@profvince.com>
Fri, 13 Mar 2015 15:08:19 +0000 (12:08 -0300)
committerVincent Pit <vince@profvince.com>
Fri, 13 Mar 2015 15:08:19 +0000 (12:08 -0300)
This fixes RT #91248.

MANIFEST
lib/Acme/CPANAuthors/You/re_using.pm
t/11-naughty-version.t [new file with mode: 0644]
t/lib/Acme/CPANAuthors/You/re_using/TestNaughtyVersion.pm [new file with mode: 0644]

index e8bd01d3482889170cbc500149935e6f33a851a6..42615e676c62887d4420c2e78487b9e69855a2b2 100644 (file)
--- 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
index 9fbe898e382b21e77200123809a0469ce13f481a..a2474bbb14eb4f3b2b308b7cc4e26e50dc586229 100644 (file)
@@ -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 (file)
index 0000000..1cf4385
--- /dev/null
@@ -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 (file)
index 0000000..f99728c
--- /dev/null
@@ -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;