Changeset 256
- Timestamp:
- 06/23/09 18:39:30 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r219 r256 246 246 247 247 sub search { 248 my ($class, $base, %filter) = @_;248 my ($class, $base, @filter) = @_; 249 249 my @results; 250 my @parsed_filter; 251 while (my $item = shift(@filter)) { 252 # attr=foo => no extra white space ! 253 # \W is false, it is possible to have two char 254 my ($attr, $mode, $val) = $item =~ /^(\w+)(?:(\W)(.+))?$/ or next; 255 if (!$mode) { 256 $mode = '~'; 257 $val = shift(@filter); 258 } 259 push( 260 @parsed_filter, 261 { 262 attr => $attr, 263 mode => $mode, 264 val => $val, 265 } 266 ); 267 } 250 268 foreach my $id ($base->list_objects($class->type)) { 251 269 my $obj = $base->get_object($class->type, $id); 252 270 my $match = 1; 253 foreach my $field ( keys %filter) {254 my $value = $fi lter{$field};255 $base->get_field_name($class->type, $field , 'r') or next;256 my $fval = $obj->get_c_field($field ) || '';271 foreach my $field (@parsed_filter) { 272 my $value = $field->{val}; 273 $base->get_field_name($class->type, $field->{attr}, 'r') or next; 274 my $fval = $obj->get_c_field($field->{attr}) || ''; 257 275 if ($value eq '*') { 258 276 if ($fval eq '') { … … 265 283 last; 266 284 } 267 } elsif ($fval !~ m/\Q$value\E/i) { 268 $match = 0; 269 last; 285 } elsif ($field->{mode} eq '=') { 286 if ($fval ne $value) { 287 $match = 0; 288 last; 289 } 290 } elsif($field->{mode} eq '~') { 291 if ($fval !~ m/\Q$value\E/i) { 292 $match = 0; 293 last; 294 } 270 295 } 271 296 }
Note: See TracChangeset
for help on using the changeset viewer.