[Bps-public-commit] r14293 - in Prophet/trunk: . lib/Prophet/CLI lib/Prophet/CLI/Command

sartak at bestpractical.com sartak at bestpractical.com
Fri Jul 18 18:00:13 EDT 2008


Author: sartak
Date: Fri Jul 18 18:00:11 2008
New Revision: 14293

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI.pm
   Prophet/trunk/lib/Prophet/CLI/Command.pm
   Prophet/trunk/lib/Prophet/CLI/Command/Search.pm

Log:
 r64604 at onn:  sartak | 2008-07-18 17:59:42 -0400
 Allow searching by arbitrary properties (multiple search terms are just ANDed together)


Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Fri Jul 18 18:00:11 2008
@@ -61,6 +61,7 @@
         get    => 'arg',
         exists => 'has_arg',
         delete => 'delete_arg',
+        keys   => 'arg_names',
     },
 );
 
@@ -74,6 +75,7 @@
         get    => 'prop',
         exists => 'has_prop',
         delete => 'delete_prop',
+        keys   => 'prop_names',
     },
 );
 

Modified: Prophet/trunk/lib/Prophet/CLI/Command.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command.pm	Fri Jul 18 18:00:11 2008
@@ -6,8 +6,8 @@
     isa => 'Prophet::CLI',
     weak_ref => 1,
     handles => [
-        qw/args  set_arg  arg  has_arg  delete_arg/,
-        qw/props set_prop prop has_prop delete_prop/,
+        qw/args  set_arg  arg  has_arg  delete_arg  arg_names/,
+        qw/props set_prop prop has_prop delete_prop prop_names/,
         'app_handle', 'run_one_command',
     ],
 );

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Search.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Search.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Search.pm	Fri Jul 18 18:00:11 2008
@@ -28,6 +28,19 @@
                 map { return 1 if $props->{$_} =~ $regex } keys %$props;
                 return 0;
             }
+    } elsif (scalar $self->prop_names > 0) {
+        my $expected_props = $self->props;
+        return sub {
+            my $item = shift;
+            my $props = $item->get_props;
+
+            for (keys %$expected_props) {
+                return 0 if not defined $props->{$_};
+                return 0 unless $props->{$_} eq $expected_props->{$_};
+            }
+
+            return 1;
+        };
     } else {
         return sub {1}
     }



More information about the Bps-public-commit mailing list