What's the raku analog of perl 5's carp?
Asked Answered
K

2

9

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?

Kalina answered 12/1, 2020 at 23:14 Comment(1)
FWIW I'm working on a module now. Will post again once I'm done.Gilman
T
10

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
Tamarin answered 12/1, 2020 at 23:48 Comment(0)
G
3

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

Gilman answered 16/1, 2020 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.