package L; use warnings; use strict; use File::Slurp; sub include { my ($f) = @_; eval { my $e = eval qq(#line 1 "$f"\n) . read_file $f; die $@ if $@; }; if ($@) { die $@ if ref($@) ne '' or $@ =~ /stack trace:/s; my $max_depth = 30; my $err = "error loading '$f': $@stack trace:\n"; my $e = -1; my @stack; my $i; for ($i = 0 ; $i < $max_depth ; ++$i) { my ($package, $filename, $line, $subroutine) = caller($i); last unless $package; # removing two evals below every include splice(@stack, -2, 2) if @stack > 2 and $subroutine eq "L::include"; push(@stack, " $subroutine called at $filename line $line"); } $err .= join("\n", @stack, ""); $err .= "...\n" if $i == $max_depth; die $err; } } 1;