my $ret = $src_drinks->match( { sugar => "no", color => "black" } ); #### SELELCT * FROM drinks WHERE sugar LIKE "no" AND color LIKE "black"; #### # sub match # return all objects that match the requested options sub match{ my ( $self, $hashref ) = @_; my @keys = keys %{ $hashref }; if ( ( @keys == 1 ) && defined( $self->{ _matched }->{ $keys[0]."@".$hashref->{ $keys[0] } } ) ) { return $self->{ _matched }->{ $keys[0]."@".$hashref->{ $keys[0] } }; } # STEP 2: now go through all objects and return ptr to list of matched objects or 0, if none found. my @ret; foreach my $obj ( @{ $self->get_data() } ) { my $equals = 1; foreach my $key ( @keys ){ my $s = "\$obj->get_".$key."()"; $equals = 0 unless ( $hashref->{ $key } eq eval( $s ) ); } push ( @ret, $obj ) if ( $equals == 1 ); } if ( @ret == 0 ){ return 0; } $self->{ _matched }->{ $keys[0]."@".$hashref->{ $keys[0] } } = \@ret if ( @keys == 1 ); return \@ret; }