-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented and tested &eval_fragment
- Loading branch information
Showing
3 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
use v5.10; | ||
use Scope::Escape::Sugar; | ||
use Devel::EvalFragment qw(eval_fragment); | ||
use B::Hooks::EndOfScope; | ||
use Test::More; | ||
|
||
my ($flag1,$flag2); | ||
sub eval_fragment { | ||
my ($code) = @_; | ||
eval("{BEGIN {B::Hooks::EndOfScope::on_scope_end { Scope::Escape::Sugar::stop_the_parse()}}\n".$code); | ||
die if $@; | ||
} | ||
sub line { | ||
my ($file,$sub,$line) = caller(0); | ||
$line; | ||
} | ||
|
||
eval_fragment('$flag1 = 42}'); | ||
is $flag1,42,'evaling code works'; | ||
eval_fragment(q[$flag2 = 66};fail("the parse isn't stopped")]); | ||
is $flag2,66,"the code after the } brace doesn't get run"; | ||
|
||
eval_fragment('$Devel::EvalFragment::Testing::flag1 = 42}'); | ||
is $Devel::EvalFragment::Testing::flag1,42,'evaling code works'; | ||
eval_fragment(q[$Devel::EvalFragment::Testing::flag2 = 66};fail("the parse isn't stopped")]); | ||
is $Devel::EvalFragment::Testing::flag2,66,"the code after the } brace doesn't get run"; | ||
sub check { | ||
my ($code,$trash) = @_; | ||
is(eval_fragment($code.'}'.$trash),length($code)+1,$code.'}'.$trash); | ||
} | ||
check '',''; | ||
check '{123}',' dsafdsfdf #$@ dfdf'; | ||
check " #1\n#2\n#3\n","#1\n#2\n#3"; | ||
done_testing; |