Created
December 28, 2016 14:15
-
-
Save regnarg/1096ad4d85e430ef2fc3c57a0e85600a to your computer and use it in GitHub Desktop.
Perl 6: Invoke a REPL in the context of the caller (debugging tool)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl6 | |
use Debug::REPLHere; | |
sub f { my $secret = 42; repl-here; say "The secret is $secret"; } | |
f | |
# Example session: | |
# $ ./example.p6 | |
# > $secret | |
# 42 | |
# > $secret=5 | |
# 5 | |
# > ^D | |
# The secret is 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit package Debug::REPLHere; | |
use nqp; | |
our sub repl-here($context=Nil) is export { | |
my $comp = nqp::getcomp('perl6'); | |
my $repl = REPL.new($comp, {}); | |
my $nqpctx := nqp::getattr(nqp::decont($context // CALLER::), PseudoStash, '$!ctx'); | |
$repl.^attributes.first('$!save_ctx').set_value($repl, $nqpctx); | |
$repl.repl-loop; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment