Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 468
Joseph Brenner Avatar asked Jan 12 '20 23:01

Joseph Brenner


2 Answers

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
like image 109
Elizabeth Mattijsen Avatar answered Nov 10 '22 01:11

Elizabeth Mattijsen


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. :-)

like image 3
user0721090601 Avatar answered Nov 09 '22 23:11

user0721090601