Name

Object::Relation::Parser - The Object::Relation parser for search requests

Synopsis

use Object::Relation::Parser      qw/parse/;
use Object::Relation::Lexer::Code qw/lexer_stream/;

sub _create_ir {
    my ($self, $search_request) = @_;
    my $stream                      = lexer_stream($search_request);
    my $intermediate_representation = parse($stream, $store);
    return $intermediate_representation;
}

Description

This class takes the tokens produced by a Object::Relation lexer and creates an intermediate representation that can be easily converted to a search request for a given store.

Exportable functions

parse

my $ir = parse($stream, $store);

This function takes a lexer stream produced by a Object::Relation lexer and the store object to be searched. It returns an intermediate representation suitable for converting into a data store search (such as a SQL WHERE clause).

This function returns an array reference of Object::Relation::Search objects and groups of these Search objects. Groups may be simple groups, "AND" groups or "OR" groups.

Simple groups

Simple groups are merely a reference to an array of search objects:

[
  $search1,
  $search2,
  $search3,
]

All searches in a simple group must succeed for the search to succeed.

AND groups

"AND" groups are array references with the string "AND" as the first element.

[
  [
    'AND',
    $search2,
    $search3,
  ]
]
OR groups

An "OR" group is the string "OR" followed by an array reference.

[
  'OR',
  [
    $search1,
    $search2,
  ]
]
Nested groups

And of the above groups may be nested.

AND(
    name   => 'foo',
    l_name => 'something',
),
OR( age => GT 3 ),
OR(
    one__type  => LIKE 'email',
    fav_number => GE 42
)

The above search, whether it is a code search or a string search, should produce the same IR:

[
  [
      'AND',
      $name_search,
      $lname_search,
  ],
  'OR',
  [
      $age_search,
  ],
  'OR',
  [
      $one_type_search,
      $fav_number_search,
  ]
]

Throws:

Object::Relation::Exception::Fatal::Search

Copyright and License

Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>

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