Commits

Anonymous committed db2a5eb

Refactoring : extracted a few methods from ::Parser::QnD.

Comments (0)

Files changed (1)

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

     return $$l =~ m{\G$re}cg;
 }
 
-sub _handle_paragraph_event
+sub _handle_open_para
 {
-    my $self = shift;
-    my $event = shift;
+    my ($self, $event) = @_;
 
-    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 => [],
-            );
+    my $new_elem = 
+        XML::Grammar::Fiction::Struct::Tag::Para->new(
+            name => "p",
+            is_standalone => 0,
+            line => $self->_get_line_num(),
+            attrs => [],
+        );
 
-        $new_elem->children([]);
+    $new_elem->children([]);
 
-        push @{$self->_tags_stack()}, $new_elem; 
+    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);
-    }
+    $self->_in_para(1);
 
     return;
 }
 
+sub _handle_close_para
+{
+    my ($self, $event) = @_;
+
+    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);
+
+    return;
+}
+
+sub _handle_paragraph_event
+{
+    my ($self, $event) = @_;
+
+    return 
+          $event->{'type'} eq "open"
+        ? $self->_handle_open_para($event)
+        : $self->_handle_close_para($event)
+        ;
+}
+
 sub _is_event_a_para
 {
-    my $self = shift;
-    my $event = shift;
+    my ($self, $event) = @_;
 
     return exists($event->{'tag'}) && ($event->{'tag'} eq "para");
 }
 
+sub _handle_elem_event
+{
+    my ($self, $event) = @_;
+
+    $self->_tags_stack->[-1]->append_children(
+        [ $event->{'elem'} ],
+    );
+
+    return;
+}
+
 sub _handle_event
 {
-    my $self = shift;
-    my $event = shift;
+    my ($self, $event) = @_;
 
     if ($self->_is_event_a_para($event))
     {
     }
     elsif ($event->{'type'} eq "elem")
     {
-        $self->_tags_stack->[-1]->append_children(
-            [ $event->{'elem'} ],
-        );
+        $self->_handle_elem_event($event);
     }
 
     return;