Commits

Shlomi Fish committed ed04f2d

Extract a method.

  • Participants
  • Parent commits 1779f82

Comments (0)

Files changed (4)

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

     $self->_writer->endTag();
 }
 
-sub _output_tag_with_childs
-{
-    my ($self, $args) = @_;
-
-    return
-        $self->_output_tag({
-            %$args,
-            'in' => sub {
-                foreach my $child (@{$args->{elem}->_get_childs()})
-                {
-                    $self->_write_elem({elem => $child,});
-                }
-            },
-        });
-}
-
 sub _output_tag_with_childs_and_common_attributes
 {
     my ($self, $elem, $tag_name, $args) = @_;
     # TODO :
     # Eliminate the Law-of-Demeter-syndrome here.
     my $list = $elem->_get_childs()->[0];
+
     $self->_output_tag(
         {
             start => ["title"],
 
 sub _write_Element_Text
 {
-    my ($self, $elem) = @_;
-
-    foreach my $child (@{$elem->_get_childs()})
-    {
-        $self->_write_elem({ elem => $child,},);
-    }
-
-    return;
+    return shift->_write_elem_childs(@_);
 }
 
 sub _write_Element_List
     my $body = $args->{'body'};
 
     my $tag = $body->name;
+
     if ($tag ne "body")
     {
         confess "Improper body tag - should be '<body>'!";
     }
 
-=begin foo
-
-    my $title =
-        first
-        { $_->name() eq "title" }
-        @{$body->_get_childs()}
-        ;
-
-    my @t =
-    (
-          defined($title)
-        ? (title => $title->_get_childs()->[0])
-        : ()
-    );
-
-=end foo
-
-=cut
-
     $self->_output_tag_with_childs_and_common_attributes(
         $body,
         'body',

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

     return [qw(Text Paragraph Element Comment)];
 }
 
+sub _output_tag_with_childs
+{
+    my ($self, $args) = @_;
+
+    return
+        $self->_output_tag({
+            %$args,
+            'in' => sub {
+                return $self->_write_elem_childs( $args->{elem} );
+            },
+        });
+}
+
+sub _write_elem_childs
+{
+    my ($self, $elem) = @_;
+
+    foreach my $child (@{$elem->_get_childs()})
+    {
+        $self->_write_elem({ elem => $child,},);
+    }
+
+    return;
+}
+
 sub _write_elem_obj
 {
     my ($self, $args) = @_;

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

     $self->_writer->endTag();
 }
 
-sub _output_tag_with_childs
-{
-    my ($self, $args) = @_;
-
-    return
-        $self->_output_tag({
-            %$args,
-            'in' => sub {
-                foreach my $child (@{$args->{elem}->_get_childs()})
-                {
-                    $self->_write_elem({elem => $child,});
-                }
-            },
-        });
-}
-
 sub _handle_text_start
 {
     my ($self, $elem) = @_;
                 elem => $elem,
             },
         );
+
+        return;
     }
     elsif ($elem->_short_isa("Description"))
     {
                 elem => $elem,
             },
         );
+
+        return;
     }
     elsif ($elem->_short_isa("Text"))
     {
-        foreach my $child (@{$elem->_get_childs()})
-        {
-            $self->_write_elem({ elem => $child,},);
-        }
+        $self->_write_elem_childs($elem);
+
+        return;
     }
     else
     {

File perl/modules/XML-Grammar-Fiction/rejects/Fiction_FromProto.pm

+package rejects::Fiction_FromProto;
+
+use strict;
+use warnings;
+
+=begin foo
+
+    my $title =
+        first
+        { $_->name() eq "title" }
+        @{$body->_get_childs()}
+        ;
+
+    my @t =
+    (
+          defined($title)
+        ? (title => $title->_get_childs()->[0])
+        : ()
+    );
+
+=end foo
+
+=cut