Commits

Anonymous committed 44b2727

XML-SemanticDifff: converted the code to an object and a class using
Non-Expat-Options. Now going to make the global variables as class members.

Comments (0)

Files changed (1)

perl/modules/XML-SemanaticDiff/lib/XML/SemanticDiff.pm

     }
     else
     {
+        my $path_finder = XML::SemanticDiff::PathFinder::Obj->new();
+        $self->{path_finder_obj} = $path_finder;
+
         my $p = XML::Parser->new(
             Style => 'Stream',
             Pkg   => 'XML::SemanticDiff::PathFinder',
             Namespaces => 1
         );
 
-        return
+        my $ret =
             $self->_is_file($xml_specifier)
                 ? $p->parsefile($xml_specifier)
                 : $p->parse($xml_specifier)
                 ;
+        
+        $self->{path_finder_obj} = undef;
+
+        return $ret;
     }
 }
 
 
 package XML::SemanticDiff::PathFinder;
 
+foreach my $func (qw(StartTag EndTag Text StartDocument EndDocument PI))
+{
+    no strict 'refs';
+    *{__PACKAGE__.'::'.$func} = sub {
+        my $expat = shift;
+        return $expat->{'Non-Expat-Options'}->{path_finder_obj}->$func(
+            $expat, @_
+        );
+    };
+}
+
+package XML::SemanticDiff::PathFinder::Obj;
+
 use strict;
 
 use Digest::MD5  qw(md5_base64);
 # The position index for the PI's below - the processing instructions.
 my $PI_position_index = {};
 
+sub new {
+    my $class = shift;
+
+    my $self = {};
+    bless $self, $class;
+
+    $self->_init(@_);
+
+    return $self;
+}
+
+sub _init {
+    return 0;
+}
+
 sub StartTag {
-    my ($expat, $element) = @_;
+    my ($self, $expat, $element) = @_;
 
 
     my %attrs = %_;
 }
 
 sub EndTag {
-    my ($expat, $element) = @_;
+    my ($self, $expat, $element) = @_;
     
     my @context = $expat->context;
 
 }
 
 sub Text {
+    my $self = shift;
     my $expat = shift;
     
     my $element = $expat->current_element;
 }
         
 sub StartDocument {
+    my $self = shift;
     my $expat = shift;
     $doc = {};
     $descendents = {};
 }
         
 sub EndDocument {
+    my $self = shift;
+
     return $doc;
 }
 
 
 sub PI {
-    my ($expat, $target, $data) = @_;
+    my ($self, $expat, $target, $data) = @_;
     my $attrs = {};
     $PI_position_index->{$target}++;