Commits

Anonymous committed 2a81203

Converted xml_context from a global to an object accessor.

  • Participants
  • Parent commits 81f5abd

Comments (0)

Files changed (1)

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

 
 use Encode qw(encode_utf8);
 
-foreach my $accessor (qw(descendents char_accumulator doc opts))
+foreach my $accessor (qw(descendents char_accumulator doc opts xml_context))
 {
     no strict 'refs';
     *{__PACKAGE__.'::'.$accessor} = sub {
     };
 }
 
-my $xml_context = [];
-
 # The position index for the PI's below - the processing instructions.
 my $PI_position_index = {};
 
     my $parent = $context[$context_length -1];
     push (@{$self->descendents()->{$parent}}, $element) if $parent;
 
-    my $last_ctx_elem = $xml_context->[-1] || { position_index => {}};
+    my $last_ctx_elem = $self->xml_context()->[-1] || { position_index => {}};
 
-    push @{$xml_context}, 
+    push @{$self->xml_context()}, 
         {
             element => "$element", 
             'index' => ++$last_ctx_elem->{position_index}->{"$element"},
 
 =cut
 
-    $test_context = _calc_test_context();
+    $test_context = $self->_calc_test_context();
 
     $self->doc()->{"$test_context"}->{NamespaceURI} = $expat->namespace($element) || "";
     $self->doc()->{"$test_context"}->{Attributes}   = \%attrs || {};
 
 sub _calc_test_context
 {
-    return "/" . join("/", map { $_->{'element'} . "[" . $_->{'index'} . "]" } @$xml_context);
+    my $self = shift;
+
+    return 
+        join("", 
+            map { "/". $_->{'element'} . "[" . $_->{'index'} . "]" } 
+            @{$self->xml_context()}
+        );
 }
 
 sub EndTag {
 
 =cut
 
-    my $test_context = _calc_test_context();
+    my $test_context = $self->_calc_test_context();
 
     my $text;
     if ( defined( $self->char_accumulator()->{$element} )) { 
     
     $self->doc()->{"$test_context"}->{TagEnd} = $expat->current_line if $self->opts()->{keeplinenums};
 
-    pop(@$xml_context);
+    pop(@{$self->xml_context()});
 }
 
 sub Text {
     $self->descendents({});
     $self->char_accumulator({});
     $self->opts($expat->{'Non-Expat-Options'});
-    $xml_context = [];
+    $self->xml_context([]);
     $PI_position_index = {};
 }