Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed 2f0bceb

Create _check_and_handle_tag_event with a loop over the tag names.

  • Participants
  • Parent commits 8558366

Comments (0)

Files changed (3)

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

     return;
 }
 
-sub _handle_event
+sub _list_valid_tag_events
 {
-    my ($self, $event) = @_;
-
-    if ($self->_is_event_a_para($event))
-    {
-        $self->_handle_para_event($event);
-    }
-    elsif ($self->_is_event_elem($event))
-    {
-        $self->_handle_elem_event($event);
-    }
-
-    return;
+    return [qw(para)];
 }
 
 before '_handle_close_tag' => sub { 

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

     return $event->type() eq "elem";
 }
 
+sub _handle_event
+{
+    my ($self, $event) = @_;
+
+    if ((! $self->_check_and_handle_tag_event($event))
+        && $self->_is_event_elem($event)
+    )
+    {
+        $self->_handle_elem_event($event);
+    }
+
+    return;
+}
+
+sub _check_and_handle_tag_event
+{
+    my ($self, $event) = @_;
+
+    foreach my $tag_name (@{$self->_list_valid_tag_events()})
+    {
+        if ($event->is_tag_of_name($tag_name))
+        {
+            my $type = $event->is_open() ? "open" : "close";
+            
+            my $method = "_handle_${type}_${tag_name}";
+
+            $self->$method($event);
+
+            return 1;
+        }
+    }
+
+    return;
+}
+
 sub _handle_para_event
 {
     my ($self, $event) = @_;

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

         : $self->_handle_close_saying();
 }
 
-sub _handle_event
+sub _list_valid_tag_events
 {
-    my ($self, $event) = @_;
-
-    if ($self->_is_event_a_para($event))
-    {
-        $self->_handle_para_event($event);
-    }
-    elsif ($self->_is_event_a_saying($event))
-    {
-        $self->_handle_saying_event($event);
-    }
-    elsif ($self->_is_event_elem($event))
-    {
-        $self->_handle_elem_event($event);
-    }
-
-    return;
+    return [qw(para saying)];
 }
 
 after '_handle_open_tag' => sub {