diff --git a/lib/Devel/REPL/Plugin/Editor.pm b/lib/Devel/REPL/Plugin/Editor.pm index 868402e..9c206ed 100644 --- a/lib/Devel/REPL/Plugin/Editor.pm +++ b/lib/Devel/REPL/Plugin/Editor.pm @@ -8,6 +8,11 @@ use File::Temp (); use namespace::clean -except => 'meta'; +has evaluating_file_contents => ( + is => 'rw', + default => 0, +); + sub command_edit { my ( $self, undef, $filename ) = @_; @@ -39,13 +44,30 @@ sub command_edit { $self->term->addhistory($pristine_code); } - return $self->formatted_eval($code); + $self->evaluating_file_contents(1); + my @result = $self->formatted_eval($code); + $self->evaluating_file_contents(0); + return @result; +} + +sub dont_allow_edit_in_file { + my ( $self, $line ) = @_; + + my $prefix = $self->default_command_prefix; + + if($self->evaluating_file_contents && $line =~ /^${prefix}edit/) { + return {}; # this will be processed by Turtles' formatted_eval, which + # should ignore it + } + + return; } sub BEFORE_PLUGIN { my ( $repl ) = @_; $repl->load_plugin('Turtles'); + $repl->add_turtles_matcher(sub { $repl->dont_allow_edit_in_file(@_) }); } 1;