Anonymous avatar Anonymous committed b6ff2f9

Extract a class for the event objects.

TODO : convert all direct field dereferences (e.g: $event->{type}) to
accessor calls.

Comments (0)

Files changed (5)

perl/modules/XML-Grammar-Fiction/MANIFEST

 lib/XML/Grammar/Fiction/App/ToHTML.pm
 lib/XML/Grammar/Fiction/Base.pm
 lib/XML/Grammar/Fiction/Err.pm
+lib/XML/Grammar/Fiction/Event.pm
 lib/XML/Grammar/Fiction/FromProto/Nodes.pm
 lib/XML/Grammar/Fiction/FromProto/Parser/LineIterator.pm
 lib/XML/Grammar/Fiction/FromProto/Parser.pm

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

+package XML::Grammar::Fiction::Event;
+
+=head1 NAME
+
+XML::Grammar::Fiction::Event - a parser event.
+
+B<For internal use only>.
+
+=cut
+
+use Moose;
+
+use XML::Grammar::Fiction::FromProto::Nodes;
+
+has 'type' => (isa => "Str", is => "ro");
+has 'tag' => (isa => "Maybe[Str]", is => "ro");
+has 'elem' => (isa => "Maybe[XML::Grammar::Fiction::FromProto::Node]", is => "ro");
+has 'tag_elem' => (isa => "Maybe[XML::Grammar::Fiction::FromProto::Node]", is => "ro");
+
+1;
+
+=head2 $self->meta()
+
+Leftover from Moose.
+
+=head1 AUTHOR
+
+Shlomi Fish, L<http://www.shlomifish.org/>.
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-xml-grammar-fiction at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Grammar-Fiction>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Shlomi Fish, all rights reserved.
+
+This program is released under the following license: MIT X11.
+
+=cut
+

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

     my $in_para = $self->_in_para();
     if ($is_para && !$in_para)
     {
-        $self->_enqueue_event({type => "open", tag => "para"});
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+               { type => "open", tag => "para", }
+            ),
+        );
         $in_para = 1;
     }
 
-    $self->_enqueue_event({type => "elem", elem => $elem});
+    $self->_enqueue_event(
+        XML::Grammar::Fiction::Event->new(
+            {type => "elem", elem => $elem}
+        )
+    );
 
     if ($is_para_end && $in_para)
     {
-        $self->_enqueue_event({ type => "close", tag => "para" });
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                { type => "close", tag => "para" }
+            )
+        );
         $in_para = 0;
     }
 

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

 
 use XML::Grammar::Fiction::Err;
 use XML::Grammar::Fiction::Struct::Tag;
+use XML::Grammar::Fiction::Event;
 
 extends("XML::Grammar::Fiction::FromProto::Parser::LineIterator");
 
 
 has "_events_queue" =>
 (
-    isa => "ArrayRef",
+    isa => "ArrayRef[XML::Grammar::Fiction::Event]",
     is => "rw", 
     default => sub { []; },
     traits => ['Array'],
             my $entity = $1;
 
             $self->_enqueue_event(
-                {
-                    type => "elem",
-                    elem => $self->_new_text(
-                        [HTML::Entities::decode_entities($entity)]
-                    ),
-                },
+                XML::Grammar::Fiction::Event->new(
+                    {
+                        type => "elem",
+                        elem => $self->_new_text(
+                            [HTML::Entities::decode_entities($entity)]
+                        ),
+                    },
+                )
             );
 
             return;
         }
 
         $self->_enqueue_event(
-            {'type' => ($self->_is_closing_tag($tag_start) ? "close" : "open")}
+            XML::Grammar::Fiction::Event->new(
+                {'type' => ($self->_is_closing_tag($tag_start) ? "close" : "open")}
+            ),
         );
 
         return 1;

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

 
     if ( ($is_saying || $is_para) && $in_para)
     {
-        $self->_enqueue_event({type => "close", tag => "para"});
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                {type => "close", tag => "para"}
+            )
+        );
         $in_para = 0;
     }
     
     if ( $is_saying && $self->_in_saying())
     {
-        $self->_enqueue_event({type => "close", tag => "saying"});
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                {type => "close", tag => "saying"}
+            )
+        );
     }
 
     if ($is_saying)
     {
         $self->_enqueue_event(
-            {type => "open", tag => "saying", _elem => $elem, },
+            XML::Grammar::Fiction::Event->new(
+                {type => "open", tag => "saying", tag_elem => $elem, },
+            ),
         );
         $was_already_enqueued = 1;
 
-        $self->_enqueue_event({type => "open", tag => "para"});
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                {type => "open", tag => "para"}
+            )
+        );
         $in_para = 1;
     }
     elsif ($is_para && !$in_para)
     {
-        $self->_enqueue_event({type => "open", tag => "para"});
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                {type => "open", tag => "para"}
+            ),
+        );
         $in_para = 1;
     }
 
     {
         if (!$in_para)
         {
-            $self->_enqueue_event({type => "open", tag => "para"});
+            $self->_enqueue_event(
+                XML::Grammar::Fiction::Event->new(
+                    {type => "open", tag => "para"},
+                )
+            );
             $in_para = 1;
         }
-        $self->_enqueue_event({type => "elem", elem => $elem, });
+        $self->_enqueue_event(
+            XML::Grammar::Fiction::Event->new(
+                {type => "elem", elem => $elem, }
+            )
+        );
         $was_already_enqueued = 1;
     }
 
                 # TODO : propagate the correct line_num
                 # from the called-to layers.
                 line => $self->line_num(),
-                attrs => [{key => "character", value => $event->{_elem}->character()}],
+                attrs => [{key => "character", value => $event->tag_elem->character()}],
             }
         );
 
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.