Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed 9383b0a

Refactoring: extract the _handle_event method.

  • Participants
  • Parent commits 46e66ba

Comments (0)

Files changed (1)

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

     return $$l =~ m{\G$re}cg;
 }
 
+sub _handle_event
+{
+    my $self = shift;
+    my $event = shift;
+
+    if (  exists($event->{'tag'})
+        && $event->{'tag'} eq "para"
+    )
+    {
+        if ($event->{'type'} eq "open")
+        {
+            my $new_elem = 
+                XML::Grammar::Fiction::Struct::Tag::Para->new(
+                    name => "p",
+                    is_standalone => 0,
+                    line => $self->_get_line_num(),
+                    attrs => [],
+                );
+
+            $new_elem->children([]);
+
+            push @{$self->_tags_stack()}, $new_elem; 
+
+            $self->_in_para(1);
+        }
+        else
+        {
+            my $open = pop(@{$self->_tags_stack()});
+
+            my $new_elem =
+                $self->_new_para(
+                    $open->detach_children(),
+                );
+
+            $self->_tags_stack->[-1]->append_children([ $new_elem ]);
+
+            $self->_in_para(0);
+        }
+    }
+    elsif ($event->{'type'} eq "elem")
+    {
+        $self->_tags_stack->[-1]->append_children(
+            [ $event->{'elem'} ],
+        );
+    }
+
+    return;
+}
+
 sub _parse_tags
 {
     my $self = shift;
 
             foreach my $event (@$contents)
             {
-                if (  exists($event->{'tag'})
-                    && $event->{'tag'} eq "para"
-                )
-                {
-                    if ($event->{'type'} eq "open")
-                    {
-                        my $new_elem = 
-                            XML::Grammar::Fiction::Struct::Tag::Para->new(
-                                name => "p",
-                                is_standalone => 0,
-                                line => $self->_get_line_num(),
-                                attrs => [],
-                            );
-
-                        $new_elem->children([]);
-
-                        push @{$self->_tags_stack()}, $new_elem; 
-
-                        $self->_in_para(1);
-                    }
-                    else
-                    {
-                        my $open = pop(@{$self->_tags_stack()});
-
-                        my $new_elem =
-                            $self->_new_para(
-                                $open->detach_children(),
-                            );
-
-                        $self->_tags_stack->[-1]->append_children([ $new_elem ]);
-
-                        $self->_in_para(0);
-                    }
-                }
-                elsif ($event->{'type'} eq "elem")
-                {
-                    $self->_tags_stack->[-1]->append_children(
-                        [ $event->{'elem'} ],
-                    );
-                }
+                $self->_handle_event($event);
             }
         }
     }