Anonymous avatar Anonymous committed 12969c1

Convert Fiction::FromProto to a named-method-dispatch.

Comments (0)

Files changed (1)

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

                 elem => $elem,
             }
         );
+        return;
     }
-    elsif ($elem->name() eq "title")
+    else
     {
-        # TODO :
-        # Eliminate the Law-of-Demeter-syndrome here.
-        my $list = $elem->_get_childs()->[0];
-        $self->_output_tag(
-            {
-                start => ["title"],
-                in => sub {
-                    $self->_write_elem(
-                        {
-                            elem => $list,
-                        }                            
-                    ),
-                },
+        my $method = "_handle_elem_of_name_" . $elem->name();
+
+        $self->$method($elem);
+
+        return;
+    }
+}
+
+sub _handle_elem_of_name_title
+{
+    my ($self, $elem) = @_;
+
+    # TODO :
+    # Eliminate the Law-of-Demeter-syndrome here.
+    my $list = $elem->_get_childs()->[0];
+    $self->_output_tag(
+        {
+            start => ["title"],
+            in => sub {
+                $self->_write_elem(
+                    {
+                        elem => $list,
+                    }                            
+                ),
             },
-        );
-    }
-    elsif ($elem->name() eq "s")
-    {
-        $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 => ["b"],
-                elem => $elem,
-            }
-        );
-    }
-    elsif ($elem->name() eq "i")
-    {
-        $self->_output_tag_with_childs(
-            {
-                start => ["i"],
-                elem => $elem,
-            }
-        );
-    }        
-    elsif ($elem->name() eq "br")
-    {
-        $self->_writer->emptyTag("br");
-    }
+        },
+    );
+
+    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) = @_;
+
+    $self->_output_tag_with_childs(
+        {
+            start => ["b"],
+            elem => $elem,
+        }
+    );
+}
+
+sub _handle_elem_of_name_i
+{
+    my ($self, $elem) = @_;
+
+    $self->_output_tag_with_childs(
+        {
+            start => ["i"],
+            elem => $elem,
+        }
+    );
+
+    return;
+}
+
+sub _handle_elem_of_name_br
+{
+    my ($self, $elem) = @_;
+
+    $self->_writer->emptyTag("br");
 
     return;
 }
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.