Anonymous avatar Anonymous committed b3e2f67

Refactoring: extracted the _find_next_inner_text method.

Comments (0)

Files changed (1)

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm

     return $self->_create_elem($open);
 }
 
+sub _find_next_inner_text
+{
+    my $self = shift;
+
+    my $which_tag;
+    my $text = "";
+
+    my $l = $self->_curr_line_ref();
+
+    # Apparently, perl does not always returns true in this
+    # case, so we need the defined($1) ? $1 : "" workaround.
+    $$l =~ m{\G([^\<\[\]\&]*)}cgms;
+
+    $text .= (defined($1) ? $1 : "");
+
+    if ($$l =~ m{\G\&})
+    {
+        $which_tag = "entity";
+    }                
+    elsif ($$l =~ m{\G(?:</|\])})
+    {
+        $which_tag = "close";
+    }
+    elsif ($$l =~ m{\G<})
+    {
+        $which_tag = "open_tag";
+    }
+
+    return ($which_tag, $text);
+}
+
 sub _parse_inner_text
 {
     my $self = shift;
     CONTENTS_LOOP:
     while ($self->_curr_line() ne "\n")
     {
-        my $which_tag;
-        # We need this to avoid appending the rest of the first line 
-        $self->_with_curr_line(
-            sub {
-                my $l = shift;
-                
-                # Apparently, perl does not always returns true in this
-                # case, so we need the defined($1) ? $1 : "" workaround.
-                $$l =~ m{\G([^\<\[\]\&]*)}cgms;
+        my ($which_tag, $text_to_append) = $self->_find_next_inner_text();
 
-                $curr_text .= (defined($1) ? $1 : "");
-
-                if ($$l =~ m{\G\&})
-                {
-                    $which_tag = "entity";
-                }                
-                elsif ($$l =~ m{\G(?:</|\])})
-                {
-                    $which_tag = "close";
-                }
-                elsif ($$l =~ m{\G<})
-                {
-                    $which_tag = "open_tag";
-                }
-            }
-        );
+        $curr_text .= $text_to_append;
 
         push @contents, $curr_text;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.