summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-01-04 16:40:10 -0600
committerJesse Luehrs <doy@tozt.net>2012-01-04 16:40:10 -0600
commit73b6d62558003113da61a5e5926ea67aa47c6ae5 (patch)
treea0313a65c21ee67e6e90ea7fc30e2ab63b01bf1d
parent8322efee06fbf44b8a8fa3717f933bae3632073d (diff)
downloadcircular-require-73b6d62558003113da61a5e5926ea67aa47c6ae5.tar.gz
circular-require-73b6d62558003113da61a5e5926ea67aa47c6ae5.zip
don't hang if all packages are hidden
-rw-r--r--lib/circular/require.pm8
-rw-r--r--t/hide_middleman3.t26
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/circular/require.pm b/lib/circular/require.pm
index b7f71c2..234be83 100644
--- a/lib/circular/require.pm
+++ b/lib/circular/require.pm
@@ -62,8 +62,12 @@ sub _require {
my $depth = 0;
my $caller;
- $caller = caller( $depth++ )
- while !$caller || grep { m/^$caller$/ } @hide;
+ do {
+ $caller = caller($depth++)
+ } while defined($caller) && grep { m/^$caller$/ } @hide;
+
+ $caller = '<unknown package>'
+ unless defined $caller;
warn "Circular require detected: $string_file (from $caller)\n";
}
diff --git a/t/hide_middleman3.t b/t/hide_middleman3.t
new file mode 100644
index 0000000..bbd920f
--- /dev/null
+++ b/t/hide_middleman3.t
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib 't/hide_middleman';
+use Test::More;
+
+no circular::require -hide => [
+ qw(base Foo Bar main circular::require),
+ (map { my $m = $_; $m =~ s+/+::+g; $m =~ s/\.pm$//; $m } keys %INC),
+];
+
+my @warnings;
+
+{
+ $SIG{__WARN__} = sub { push @warnings => @_ };
+
+ use_ok( 'Foo' );
+}
+
+is_deeply(
+ \@warnings,
+ ["Circular require detected: Foo.pm (from <unknown package>)\n"],
+ "don't loop infinitely if all packages are hidden"
+);
+
+done_testing;