What's the raku analog of perl 5's carp?

231 Views Asked by At

By default, Raku's "die" reports the line number where the "die" is located, what if you'd like the line number of the calling context, ala "carp" with perl 5?

2

There are 2 best solutions below

0
On

There is no direct equivalent to carp, but you can start raku with the --ll-exception parameter, which will create a full stack trace on an execution error.

I guess nobody has gotten around to creating a Carp module yet. Creating a carp sub shouldn't be too difficult, given that there is a Backtrace class:

$ raku -e 'say "file: {.file}:{.line}" for Backtrace.new' 
file: SETTING::src/core.c/Backtrace.pm6:94
file: SETTING::src/core.c/Backtrace.pm6:94
file: -e:1
0
On

There is now a Carp module available on GitHub and should soon be available in the Raku ecosystem. It currently only supports the most basic functionality, but over time it should be improved.

So the answer to your question is to use Carp like you would in Perl 5. :-)