コードを引数に渡して、evalで実行しちゃう感じです。
#!/usr/bin/perl use warnings; use strict; use Devel::EvalContext; my $cxt = Devel::EvalContext->new(); my $hoge =$cxt->run(q{my $foo = "hoge";}); $cxt->run(q{print $foo;}); # hoge
Jifty::Script::Console?というモジュールで使われています。ちょとした開発時に役にたつかも?
sub run { my $self = shift; Jifty->new(); my $term = new Term::ReadLine 'Jifty Console'; my $OUT = $term->OUT || \*STDOUT; my $cxt = Devel::EvalContext->new; while (defined($_ = $term->readline("jifty> "))) { if (/\S/) { my $res = $cxt->run($_); warn $@ if $@; print $OUT $res, "\n" unless $@ || !defined($res); $term->addhistory($_); } } }
タグ
このページへのコメント
gZGqtq Major thanks for the blog article.Much thanks again. Much obliged.
tbKLq6 I cannot thank you enough for the blog.Really looking forward to read more. Really Cool.