[Bps-public-commit] r18034 - Parse-BooleanLogic/lib/Parse

ruz at bestpractical.com ruz at bestpractical.com
Thu Jan 29 08:36:13 EST 2009


Author: ruz
Date: Thu Jan 29 08:36:13 2009
New Revision: 18034

Modified:
   Parse-BooleanLogic/lib/Parse/BooleanLogic.pm

Log:
* add walk method

Modified: Parse-BooleanLogic/lib/Parse/BooleanLogic.pm
==============================================================================
--- Parse-BooleanLogic/lib/Parse/BooleanLogic.pm	(original)
+++ Parse-BooleanLogic/lib/Parse/BooleanLogic.pm	Thu Jan 29 08:36:13 2009
@@ -680,6 +680,22 @@
     return $res;
 }
 
+sub walk {
+    my ($self, $tree, $cb, @rest) = @_;
+
+    foreach my $entry ( @$tree ) {
+        if ( ref $entry eq 'ARRAY' ) {
+            $cb->{'open_paren'}->( @rest ) if $cb->{'open_paren'};
+            $self->walk( $entry, $cb, @rest );
+            $cb->{'close_paren'}->( @rest ) if $cb->{'close_paren'};
+        } elsif ( ref $entry eq 'HASH' ) {
+            $cb->{'operand'}->( $entry, @rest ) if $cb->{'operand'};
+        } else {
+            $cb->{'operator'}->( $entry, @rest ) if $cb->{'operator'};
+        }
+    }
+}
+
 1;
 
 =head1 ALTERNATIVES



More information about the Bps-public-commit mailing list