Commits

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

Convert Screenplay to a named-method-dispatch and extract some common methods.

  • Participants
  • Parent commits 12969c1

Comments (0)

Files changed (3)

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

     return "p";
 }
 
-sub _write_Element_elem
-{
-    my ($self, $elem) = @_;
-
-    if ($elem->_short_isa("InnerDesc"))
-    {
-        $self->_output_tag_with_childs(
-            {
-                start => ["inlinedesc"],
-                elem => $elem,
-            }
-        );
-        return;
-    }
-    else
-    {
-        my $method = "_handle_elem_of_name_" . $elem->name();
-
-        $self->$method($elem);
-
-        return;
-    }
-}
-
 sub _handle_elem_of_name_title
 {
     my ($self, $elem) = @_;
     return;
 }
 
-sub _handle_elem_of_name_s
-{
-    my ($self, $elem) = @_;
-
-    $self->_write_scene({scene => $elem});
-}
-
-sub _handle_elem_of_name_a
-{
-    my ($self, $elem) = @_;
-    $self->_output_tag_with_childs(
-        {
-            start => ["ulink", "url" => $elem->lookup_attr("href")],
-            elem => $elem,
-        }
-    );
-
-    return;
-}
-
 sub _handle_elem_of_name_b
 {
     my ($self, $elem) = @_;
     return;
 }
 
-sub _handle_elem_of_name_br
-{
-    my ($self, $elem) = @_;
-
-    $self->_writer->emptyTag("br");
-
-    return;
-}
 
 sub _handle_text_start
 {

File perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/TagsTree2XML.pm

 
 has '_buffer' => ('isa' => "ScalarRef[Str]", is => "rw");
 
+sub _write_Element_elem
+{
+    my ($self, $elem) = @_;
+
+    if ($elem->_short_isa("InnerDesc"))
+    {
+        $self->_output_tag_with_childs(
+            {
+                start => ["inlinedesc"],
+                elem => $elem,
+            }
+        );
+        return;
+    }
+    else
+    {
+        my $method = "_handle_elem_of_name_" . $elem->name();
+
+        $self->$method($elem);
+
+        return;
+    }
+}
+    
+sub _handle_elem_of_name_s
+{
+    my ($self, $elem) = @_;
+
+    $self->_write_scene({scene => $elem});
+}
+
+sub _handle_elem_of_name_a
+{
+    my ($self, $elem) = @_;
+    $self->_output_tag_with_childs(
+        {
+            start => ["ulink", "url" => $elem->lookup_attr("href")],
+            elem => $elem,
+        }
+    );
+
+    return;
+}
+
+sub _handle_elem_of_name_br
+{
+    my ($self, $elem) = @_;
+
+    $self->_writer->emptyTag("br");
+
+    return;
+}
 
 =head2 meta()
 

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

     return "para";
 }
 
-sub _write_Element_elem
+sub _handle_elem_of_name_section
 {
     my ($self, $elem) = @_;
 
-    if ($elem->_short_isa("InnerDesc"))
-    {
-        $self->_output_tag_with_childs(
-            {
-                start => ["inlinedesc"],
-                elem => $elem,
-            }
-        );
-    }
-    elsif (($elem->name() eq "s") || ($elem->name() eq "section"))
-    {
-        $self->_write_scene({scene => $elem});
-    }
-    elsif ($elem->name() eq "a")
-    {
-        $self->_output_tag_with_childs(
-            {
-                start => ["ulink", "url" => $elem->lookup_attr("href")],
-                elem => $elem,
-            }
-        );
-    }
-    elsif ($elem->name() eq "b")
-    {
-        $self->_output_tag_with_childs(
-            {
-                start => ["bold"],
-                elem => $elem,
-            }
-        );
-    }
-    elsif ($elem->name() eq "br")
-    {
-        $self->_writer->emptyTag("br");
-    }
+    return $self->_handle_elem_of_name_s($elem);
+}
+
+# TODO : extract a common method with different class constants.
+sub _handle_elem_of_name_b
+{
+    my ($self, $elem) = @_;
+
+    $self->_output_tag_with_childs(
+        {
+            start => ["bold"],
+            elem => $elem,
+        }
+    );
 
     return;
 }