Carp::REPL(3)
π Carp::REPL π
okay so bestie, welcome to Carp::REPL β that's the Perl module living in the User Contributed Perl Documentation section of your manual (you'd have found it as Carp::REPL(3) in the header, slay). What does it do? It gives you a read-eval-print-loop on die and/or warn. Like, your program crashes and instead of just dying dramatically, you get a whole interactive vibe check. iconic.
β¨ NAME β¨
Carp::REPL β read-eval-print-loop on die and/or warn. periodt.
πΈ SYNOPSIS πΈ
the intended way to use this module is through the command line. (iykyk)
perl -MCarp::REPL tps-report.pl
Can't call method "cover_sheet" without a package or object reference at tps-report.pl line 6019.
and then, instead of exiting, you get a REPL! bestie that's the whole point π
$ $form
27B/6
$ $self->get_form
27B/6
$ "ah ha! there's my bug, I thought get_form returned an object"
ah ha! there's my bug, I thought get_form returned an object
π¦ USAGE π¦
π -MCarp::REPL
π -MCarp::REPL=warn
works as a command line argument. it automatically installs the die handler for you, so if you get a fatal error you get a REPL before the universe explodes. specifying =warn also installs a warn handler, for sniffing out those mysterious warnings. obsessed.
π use Carp::REPL;
π use Carp::REPL 'warn';
same as above, fr fr.
π use Carp::REPL 'nodie';
loads the module without installing the die handler. use this if you just wanna run Carp::REPL::repl on your own terms, main character energy.
π use Carp::REPL 'test';
π -MCarp::REPL=test
load a REPL on test failure! (as long as it uses ok in Test::More). yes bestie, your failing tests get a whole glow-up.
β FUNCTIONS β
π repl
this module's interface consists of exactly one function: repl. it's provided so you may install your own $SIG{__DIE__} handler if you have no alternatives.
it takes the same arguments as die, and returns no useful value. in fact, don't even depend on it returning at all! like, it might just dip.
one useful place for calling this manually is if you just wanna check the state of things without having to throw a fake error. you can also change any variables and those changes will be seen by the rest of your program. lowkey powerful.
use Carp::REPL 'repl';
sub involved_calculation {
# ...
$d = maybe_zero();
# ...
repl(); # $d = 1
$sum += $n / $d;
# ...
}
unfortunately, if you instead go with the usual -MCarp::REPL, then $SIG{__DIE__} will be invoked and there's no general way to recover. π but you can still change variables to poke at things. it's giving "not ideal but we work with it".
π COMMANDS π
note that this is not supposed to be a full-fledged debugger. a few commands are provided to aid you in finding out what went awry. see Devel::ebug if you're looking for a serious debugger. this one's just here for the plot.
:uβ moves one frame up in the stack.:dβ moves one frame down in the stack.:topβ moves to the top frame of the stack.:bottomβ moves to the bottom frame of the stack.:tβ redisplay the stack trace.:eβ display the current lexical environment.:lβ list eleven lines of source code of the current frame.:qβ close the REPL. (^Dalso works)
π VARIABLES π
$_REPLβ this represents theDevel::REPLobject.$_aβ this represents the arguments passed to the subroutine at the current frame in the call stack. modifications are ignored (how would that work anyway?? re-invoke the sub?? bestie pls).
π CAVEATS π
dynamic scope probably produces unexpected results. i don't see any easy (or even difficult!) solution to this. therefore it's a caveat and not a bug. :) we love a self-aware disclaimer.
heads up: dynamic scope + unexpected results = chaos. it's documented on purpose, not fixed on purpose. iykyk.
π§ SEE ALSO π§
Devel::REPL, Devel::ebug, Enbugger, CGI::Inspect
π AUTHOR π
Shawn M Moore, "<sartak at gmail.com>"
π BUGS π
please report any bugs or feature requests to "bug-carp-repl at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Carp-REPL>.
π«Ά ACKNOWLEDGEMENTS π«Ά
thanks to Nelson Elhage and Jesse Vincent for the idea.
thanks to Matt Trout and Stevan Little for their advice.
π COPYRIGHT & LICENSE π
copyright 2007-2008 Best Practical Solutions.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π
this gorgeousness dropped with perl v5.42.0 and is dated 2025-07-25 β go forth and REPL responsibly, no cap πβ¨π
π¦ where this page comes from
- fedora 43: perl-Carp-REPL 0.18-30.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms