in reply to print stack of "do" files on error
Hi kir,
One way to do this is with caller. Also I've included the error checking suggested in do.
sub include { my $file = shift; unless (my $return = do $file) { my (undef, $callerfile, $callerline) = caller; my $from = "included from $callerfile line $callerline"; die "Couldn't parse $file, $from:\n$@" if $@; die "Couldn't do $file, $from: $!" unless defined $return; die "Couldn't run $file, $from" unless $return; } }
Using some test code in which test.pl uses include on A.pm, which in turn includes B.pm, then X.pm with a die, I get this output:
Couldn't parse A.pm, included from test.pl line 8: Couldn't parse B.pm, included from A.pm line 7: Couldn't parse X.pm, included from B.pm line 7: Blammo at X.pm line 6.
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: print stack of "do" files on error
by kir (Initiate) on Apr 04, 2016 at 05:04 UTC | |
by haukex (Archbishop) on Apr 05, 2016 at 22:43 UTC |