NAME
Salvation::MacroProcessor::Spec - Query object
REQUIRES
METHODS
parse_and_new
Salvation::MacroProcessor::Spec -> parse_and_new( $class_or_object, $query );
Creates and returns new query object, an instance of Salvation::MacroProcessor::Spec class.
$class_or_object
is a class name or instance of the class which will be the base class for the query. It has been thought of as "I will check or select objects of that type".
$query
is an object of type ArrayRef[ArrayRef[Any]]. It is the query you want to perform. Each inner ArrayRef represents a filter, a field which consists of two parameters: the first is the name and the second is the value. Imagine you have following $query
object:
[
[ method => $value ]
]
. method
here is the name of the method description which will be the part of the query, and $value
is the value for this column, a condition for a filter. It should be thought of as "I want to select an object which method()' call returns the $value".
I.e., a query with two fields will look somewhat like this:
[
[ method1 => $value1 ],
[ method2 => $value2 ]
]
. Note this very explicit separation of fields.
select
$spec -> select();
Selects objects.
check
$spec -> check( $object );
Checks if given $object
could be selected using this $spec
.
$object
is an object representing a single row of data returned by the query.
new
Salvation::MacroProcessor::Spec -> new(
class => $class,
fields => $fields
)
Constructor.
Returns Salvation::MacroProcessor::Spec instance.
All arguments are required.
Arguments:
- class
-
String (could be coerced from Object though), the name of base class for this query.
- fields
-
ArrayRef[Salvation::MacroProcessor::Field], list of fields used in this query.
add_field
$spec -> add_field( $field )
Add field to the list.
$field
is a Salvation::MacroProcessor::Field instance.
all_fields
$spec -> all_fields()
Returns an array of all fields (each is a Salvation::MacroProcessor::Field instance) used in the query.
fields
$spec -> fields()
Returns an ArrayRef of all fields (each is a Salvation::MacroProcessor::Field instance) used in the query.
query
$spec -> query()
Processes fields, aggregates query parts and returns an ArrayRef which contains the final query.
All aggregations and processing here are done only once per object instance, so the second call to query
of the same object instance will be much faster than first.