The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Search::QS::Filter - Incapsulation of a single filter element

VERSION

version 0.03

SYNOPSIS

  use Search::QS::Filter;

  my $flt = new Search::QS::Filter;
  # parse query_string
  $flt->parse_qs($qs);
  # reconvert object to query_string
  print $flt->to_qs;

DESCRIPTION

This object incapsulate a single filter element. Think of it about a single search element in an SQL string. Like

  fullname = "Joe"

it has a fied "name()" "fullname", an "operator()" "=" and a "value()" "Joe".

METHODS

name()

The field name to search

operator()

The operator to use between field and value

value()

An ARRAYREF with values to search in field name. It should be expanded with OR concatenation. As an example,

  fld[x]=1&fld[x]=2

after parsing produce

    name => 'x', values => [1,2]

and in SQL syntax must be written like

  x=1 or x=2

tag()

In field name it can be use ":" to separe field name by a tag. The idea is to distinguish different operation with same field name.

As an example

  fld[a:1]=1&fld[a:1]=$op:>&fld[a:2]=5&fld[a:2]=$op:<

must be

  a>1 and a<5

andGroup()

If you set a field with $and:$groupvalue you set that this field in a AND group with other fields with same $groupvalue

As an example to

  flt[d:1]=9&flt[d:1]=$and:1&flt[c:1]=2&flt[c:1]=$and:1&flt[d:2]=3&flt[d:2]=$and:2&flt[c:2]=1&flt[c:2]=$and:2

is traslated in

( d=9 AND c=2 ) OR ( d=3 and c=1 )

orGroup()

Like "andGroup()" but for OR operator

parse($perl_struct)

$perl_struct is an HASHREF which represents a query string like the one returned by "url_params_mixed" in URI::Encode. It parses the struct and extract filter informations

to_qs()

Return a query string of the internal rappresentation of the object

to_sql

Return this object as a SQL search

AUTHOR

Emiliano Bruni <info@ebruni.it>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Emiliano Bruni.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.