Allow extracting strings going over multiple lines using scan_str.
Florian Ragwitz [Sat, 18 Apr 2009 08:42:06 +0000 (08:42 +0000)]
Declare.xs
lib/Devel/Declare/Context/Simple.pm

index d29488d..08bbec6 100644 (file)
@@ -187,8 +187,17 @@ int dd_toke_scan_ident(pTHX_ int offset) {
 }
 
 int dd_toke_scan_str(pTHX_ int offset) {
+  int remaining = sv_len(PL_linestr) - offset;
+  SV* line_copy = newSVsv(PL_linestr);
   char* base_s = SvPVX(PL_linestr) + offset;
   char* s = scan_str(base_s, FALSE, FALSE);
+  if (s != base_s && sv_len(PL_lex_stuff) > remaining) {
+    int ret = (s - SvPVX(PL_linestr)) + remaining;
+    sv_catsv(line_copy, PL_linestr);
+    dd_set_linestr(aTHX_ SvPV_nolen(line_copy));
+    SvREFCNT_dec(line_copy);
+    return ret;
+  }
   return s - base_s;
 }
 
index 52dd70d..1a47a7f 100644 (file)
@@ -92,14 +92,7 @@ sub strip_proto {
     my $length = Devel::Declare::toke_scan_str($self->offset);
     my $proto = Devel::Declare::get_lex_stuff();
     Devel::Declare::clear_lex_stuff();
-    if( $length < 0 ) {
-      # Need to scan ahead more
-      $linestr .= $self->get_linestr();
-      $length = rindex($linestr, ")") - $self->offset + 1;
-    }
-    else {
-      $linestr = $self->get_linestr();
-    }
+    $linestr = $self->get_linestr();
 
     substr($linestr, $self->offset, $length) = '';
     $self->set_linestr($linestr);