[Bps-public-commit] r14546 - in Prophet/trunk: .
sartak at bestpractical.com
sartak at bestpractical.com
Sun Jul 27 11:53:23 EDT 2008
Author: sartak
Date: Sun Jul 27 11:53:22 2008
New Revision: 14546
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/CLI/Command/Search.pm
Log:
r65244 at onn: sartak | 2008-07-27 11:51:46 -0400
Refactor the search code so you can specify both --regex and some props
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 Sun Jul 27 11:53:22 2008
@@ -11,23 +11,18 @@
sub get_search_callback {
my $self = shift;
- if ( my $regex = $self->arg('regex') ) {
- return sub {
- my $item = shift;
- my $props = $item->get_props;
- map { return 1 if $props->{$_} =~ $regex } keys %$props;
- return 0;
- }
- } elsif (scalar $self->prop_names > 0) {
- my %prop_checks;
- for my $check ($self->prop_set) {
- push @{ $prop_checks{ $check->{prop} } }, $check;
- }
+ my %prop_checks;
+ for my $check ($self->prop_set) {
+ push @{ $prop_checks{ $check->{prop} } }, $check;
+ }
- return sub {
- my $item = shift;
- my $props = $item->get_props;
+ my $regex = $self->arg('regex');
+ return sub {
+ my $item = shift;
+ my $props = $item->get_props;
+
+ if ($self->prop_names > 0) {
for my $prop (keys %prop_checks) {
my $got = $props->{$prop};
my $ok = 0;
@@ -37,12 +32,22 @@
}
return 0 if !$ok;
}
+ }
+
+ # if they specify a regex, it must match
+ if ($regex) {
+ my $ok = 0;
+ for (values %$props) {
+ if (/$regex/) {
+ $ok = 1;
+ last;
+ }
+ }
+ return 0 if !$ok;
+ }
- return 1;
- };
- } else {
- return sub {1}
- }
+ return 1;
+ };
}
sub cmp_ok {
More information about the Bps-public-commit
mailing list