NAME
Salvation::MacroProcessor::Hooks - Base class for your hooks with implementation of actual logic for Salvation::MacroProcessor::Spec
DESCRIPTION
Salvation::MacroProcessor::Hooks-derived classes are a place for your implementation of actual query execution logic. As Salvation::MacroProcessor::Spec aggregates query parts in a complete query for you, you should then do something with aggregated query by yourself.
For the system to work properly, your hook class should have specific name made using following pattern:
sprintf( 'Salvation::MacroProcessor::Hooks::%s', $your_class_name )
, where $your_class_name
is the name of a class you want to have Salvation::MacroProcessor support.
Your hook will be loaded automatically when it need to be loaded.
If there is no hook for current class, but there is hook for one of parent classes - this hook will be used, so you can define one parent class with Salvation::MacroProcessor support and just inherit this class by other classes so each child won't need to have its own hook.
Example usage
package Salvation::MacroProcessor::Hooks::MyClass;
use Moose;
extends 'Salvation::MacroProcessor::Hooks';
no Moose;
REQUIRES
METHODS
To be redefined
You can redefine following methods to achieve your own goals.
check
$hook -> check( $spec, $object );
Checks if given $object
could be selected using this $spec
.
$spec
is a Salvation::MacroProcessor::Spec instance.
$object
is an object representing a single row of data returned by the query.
Boolean value should be returned, false
means "skip this object" and true
means "yes, this object is what we want".
query_from_attribute
$hook -> query_from_attribute( $method_description, $attr, @rest );
Generates query part which needs to be applied to the query to get an object which satisfies specified criteria.
This method will be called if all following conditions are true:
- class has an attribute (see Moose::Manual::Attributes for more info) which name is exactly the same as the method being described
- description has no
query
argument specified
$method_description
is a Salvation::MacroProcessor::MethodDescription instance.
$attr
is a Moose::Meta::Attribute instance.
@rest
is a list of arguments of the same types, conditions and meaning as it is for query
argument of Salvation::MacroProcessor::smp_add_description
when $query
is a CodeRef.
Return value should also be as the one of $query
function of Salvation::MacroProcessor::smp_add_description
.
select
$hook -> select( $spec, $additional_query, $additional_args );
Selects objects using given $spec
with a mix of $additional_query
and $additional_args
.
$spec
is a Salvation::MacroProcessor::Spec instance.
$additional_query
and $additional_args
are both passed in by you or any other developer who will try to make a query. Though both are thought of as ArrayRef's.
$additional_query
's meaning is "some custom query part we need to apply to the query".
$additional_args
's meaning is "some additional custom arguments we need to pass to the method which will then perform a request to complete the query".
Return value will be returned directly to caller which is your custom code issued Salvation::MacroProcessor::Spec::select
. Though return value is thought of as Salvation::MacroProcessor::Iterator instance.