diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-01-06 01:14:29 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-01-06 01:15:25 -0600 |
commit | d0719e8ad715588446409155d68fd1783486aa69 (patch) | |
tree | 71121b793602fba6ffad170dba646cc882bf4e3b /lib | |
parent | de76247745ea63176649888b4ef40be01ce3cd16 (diff) | |
download | circular-require-d0719e8ad715588446409155d68fd1783486aa69.tar.gz circular-require-d0719e8ad715588446409155d68fd1783486aa69.zip |
show the entire cycle in the warning0.06
Diffstat (limited to 'lib')
-rw-r--r-- | lib/circular/require.pm | 18 |
1 files changed, 12 insertions, 6 deletions
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 = '<unknown file>'; - 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; |