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

ruz at bestpractical.com ruz at bestpractical.com
Fri Nov 21 16:55:15 EST 2008


Author: ruz
Date: Fri Nov 21 16:55:15 2008
New Revision: 16965

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

Log:
* respecp custom operators in solve and fsolve

Modified: Parse-BooleanLogic/lib/Parse/BooleanLogic.pm
==============================================================================
--- Parse-BooleanLogic/lib/Parse/BooleanLogic.pm	(original)
+++ Parse-BooleanLogic/lib/Parse/BooleanLogic.pm	Fri Nov 21 16:55:15 2008
@@ -445,12 +445,14 @@
 sub solve {
     my ($self, $tree, $cb) = @_;
 
-    my ($res, $ea, $skip_next) = (0, 'OR', 0);
+    my ($res, $ea, $skip_next) = (0, $self->{'operators'}[1], 0);
     foreach my $entry ( @$tree ) {
         $skip_next-- and next if $skip_next > 0;
         unless ( ref $entry ) {
-            $ea = $entry;
-            $skip_next++ if ($res && $ea eq 'OR') || (!$res && $ea eq 'AND');
+            $ea = lc $entry;
+            $skip_next++ if
+                   ( $res && $ea eq $self->{'operators'}[1])
+                || (!$res && $ea eq $self->{'operators'}[0]);
             next;
         }
 
@@ -460,7 +462,7 @@
         } else {
             $cur = $cb->( $entry );
         }
-        if ( $ea eq 'OR' ) {
+        if ( $ea eq $self->{'operators'}[1] ) {
             $res ||= $cur;
         } else {
             $res &&= $cur;
@@ -483,12 +485,14 @@
 sub fsolve {
     my ($self, $tree, $cb) = @_;
 
-    my ($res, $ea, $skip_next) = (undef, 'OR', 0);
+    my ($res, $ea, $skip_next) = (undef, $self->{'operators'}[1], 0);
     foreach my $entry ( @$tree ) {
         $skip_next-- and next if $skip_next > 0;
         unless ( ref $entry ) {
-            $ea = $entry;
-            $skip_next++ if ($res && $ea eq 'OR') || (!$res && $ea eq 'AND');
+            $ea = lc $entry;
+            $skip_next++ if
+                   ( $res && $ea eq $self->{'operators'}[1])
+                || (!$res && $ea eq $self->{'operators'}[0]);
             next;
         }
 
@@ -500,7 +504,7 @@
         }
         if ( defined $cur ) {
             $res ||= 0;
-            if ( $ea eq 'OR' ) {
+            if ( $ea eq $self->{'operators'}[1] ) {
                 $res ||= $cur;
             } else {
                 $res &&= $cur;



More information about the Bps-public-commit mailing list