OSSP CVS Repository

ossp - Difference in ossp-pkg/string-divert/Divert.pm versions 1.14 and 1.15
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/string-divert/Divert.pm 1.14 -> 1.15

--- Divert.pm    2005/11/16 12:08:49     1.14
+++ Divert.pm    2005/11/16 12:51:13     1.15
@@ -67,6 +67,7 @@
     $self->{diversion} = [];                                # stack of active diversions
     $self->{foldermk}  = '{#%s#}';                          # folder text representation format
     $self->{folderre}  = '\{#([a-zA-Z_][a-zA-Z0-9_]*)#\}';  # folder text representation regexp
+    $self->{folderlst} = undef;                             # folder object of last folding operation
 
     return $self;
 }
@@ -185,11 +186,13 @@
         if (not defined($obj));
     if (&String::Divert::_isobj($obj)) {
         $self->{chunks} = [ $obj ];
+        $self->{folderlst} = $obj if (ref($obj));
     }
     else {
         $self->{chunks} = [];
         foreach my $chunk ($self->_chunking($obj)) {
             push(@{$self->{chunks}}, $chunk);
+            $self->{folderlst} = $chunk if (ref($chunk));
         }
     }
     return $self;
@@ -211,11 +214,13 @@
     else {
         if (&String::Divert::_isobj($obj)) {
             push(@{$self->{chunks}}, $obj);
+            $self->{folderlst} = $obj if (ref($obj));
         }
         else {
             foreach my $chunk ($self->_chunking($obj)) {
                 if (ref($chunk) or (@{$self->{chunks}} > 0 and ref($self->{chunks}->[-1]))) {
                     push(@{$self->{chunks}}, $chunk);
+                    $self->{folderlst} = $chunk if (ref($chunk));
                 }
                 elsif (@{$self->{chunks}} > 0) {
                     $self->{chunks}->[-1] .= $chunk;
@@ -301,6 +306,7 @@
         croak "folding object not of class String::Divert"
             if (not &String::Divert::_isobj($id));
         push(@{$self->{chunks}}, $id);
+        $self->{folderlst} = $id;
         return $id;
     }
     else {
@@ -309,6 +315,7 @@
         croak "unable to create new folding object"
             if (not defined($object));
         push(@{$self->{chunks}}, $object);
+        $self->{folderlst} = $object;
         return $object;
     }
 }
@@ -320,6 +327,7 @@
         if (@{$self->{diversion}} > 0);
     my $string = $self->string();
     $self->{chunks} = $string ne '' ? [ $string ] : [];
+    $self->{folderlst} = undef;
     return $string;
 }
 
@@ -356,7 +364,7 @@
                     $folding = $chunk;
                     last;
                 }
-                $folding = $chunk->folding($id);
+                $folding = $chunk->folding($id); # recursion!
                 last if (defined($folding));
             }
         }
@@ -405,11 +413,9 @@
     my $object; $object = undef;
     if (not defined($id)) {
         #   choose last folding object
-        foreach my $chunk ($self->folding()) {
-            if (ref($chunk)) {
-                $object = $chunk;
-                last;
-            }
+        foreach my $obj (reverse ($self, @{$self->{diversion}})) {
+            $object = $obj->{folderlst};
+            last if (defined($object));
         }
         croak "no last folding sub-object found"
             if (not defined($object));
@@ -431,7 +437,7 @@
     if ($num !~ m|^\d+$|) {
         #   lookup number by name
         my $name = $num;
-        for ($num = 1; $num <= @{$self->{diversion}}; $num++) {
+        for (my $num = 1; $num <= @{$self->{diversion}}; $num++) {
             last if ($self->{diversion}->[-$num]->{name} eq $name);
         }
         croak "no object named \"$name\" found for undiversion"

CVSTrac 2.0.1