From d0719e8ad715588446409155d68fd1783486aa69 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 Jan 2012 01:14:29 -0600 Subject: show the entire cycle in the warning --- lib/circular/require.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/circular/require.pm b/lib/circular/require.pm index 5cc4657..6216653 100644 --- a/lib/circular/require.pm +++ b/lib/circular/require.pm @@ -60,17 +60,23 @@ sub _require { # string contexts at all my $string_file = $file; if (exists $loaded_from{$string_file}) { + my @cycle = ($string_file); + my $caller = $previous_file; - while (grep { m/^$caller$/ } @hide) { + while (defined($caller)) { + unshift @cycle, $caller + unless grep { /^$caller$/ } @hide; + last if $caller eq $string_file; $caller = $loaded_from{$caller}; - if (!defined($caller) || $caller eq $string_file) { - $caller = ''; - last; - } } - warn "Circular require detected: $string_file (from $caller)\n"; + if (@cycle > 1) { + warn "Circular require detected:\n " . join("\n ", @cycle) . "\n"; + } + else { + warn "Circular require detected in $string_file (from unknown file)\n"; + } } local $loaded_from{$string_file} = $previous_file; local $previous_file = $string_file; -- cgit v1.2.3-54-g00ecf