Turn MultiLine::PPI's needs_continuation into a method line_needs_continuation
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / MultiLine / PPI.pm
index f3ba897..a812b27 100644 (file)
@@ -9,17 +9,25 @@ has 'continuation_prompt' => (
   default => sub { '> ' }
 );
 
+has 'line_depth' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { 0 }
+);
+
 around 'read' => sub {
   my $orig = shift;
   my ($self, @args) = @_;
   my $line = $self->$orig(@args);
 
   if (defined $line) {
-    while (needs_continuation($line)) {
+    while ($self->line_needs_continuation($line)) {
       my $orig_prompt = $self->prompt;
       $self->prompt($self->continuation_prompt);
 
+      $self->line_depth($self->line_depth + 1);
       my $append = $self->read(@args);
+      $self->line_depth($self->line_depth - 1);
+
       $line .= $append if defined($append);
 
       $self->prompt($orig_prompt);
@@ -31,8 +39,9 @@ around 'read' => sub {
   return $line;
 };
 
-sub needs_continuation
+sub line_needs_continuation
 {
+  my $repl = shift;
   my $line = shift;
   my $document = PPI::Document->new(\$line);
   return 0 if !defined($document);