Salvation::Service::View - Base class for a view
package YourSystem::Services::SomeService::Defaults::V; use Moose; extends 'Salvation::Service::View'; no Moose;
Salvation::Roles::ServiceReference
Moose
$view_instance -> process();
Processes service's DataSet with $view_instance and sets a Salvation::Service::View::Stack instance, or an ArrayRef of those instances (depending on MULTINODE result), to view_output attribute of appropriate Salvation::Service::State instance, returning the value being set.
$view_instance
MULTINODE
view_output
$view_instance -> process_node( $object ); $view_instance -> process_node( $object, \@template );
Processes $object with $view_instance using \@template and returns Salvation::Service::View::Stack instance. @template could containt anything main's returning value could containt. Default @template contents are main's returning value' contents.
$object
\@template
@template
main
You can redefine following methods to achieve your own goals.
Should return boolean value. Tells the view if it needs to process and return many rows returned by DataSet, or just one. The only argument is $self which is current view's instance. Default value is false.
$self
Should return an ArrayRef containing template data which will be used to process objects.
Each element of an ArrayRef could be either of the following:
A text which is interpreted as the type of each column listed in an ArrayRef which follows this text, if any. Example usage:
regular_database_column => [ 'id', 'name' ]
Having this, the view knows which methods of the model it needs to call in order to process each column.
A list of column specs. Each element of such ArrayRef will be translated to model's method call. Each element of an ArrayRef could be either of the following:
A text which is interpreted as the name of the column. Here an appropriate model's method call is happening.
In example, having an element named id and column type already set to regular_database_column, the view will generate model's method name like this:
id
regular_database_column
my $type = 'regular_database_column'; my $column = 'id'; my $model_method = sprintf( '%s_%s', $type, $column );
Then the view will check if the model can( $model_method ) and, if it is true, will call this method with an $object argument where the $object is the object being processed right now.
can( $model_method )
However, if the check returned false, the view will try to generate another method name like this:
my $another_model_method = sprintf( '__%s', $type );
Then the view will check if the model can( $another_model_method ) and, if it is true, will call this method with two arguments: $object and $column where the $object is the object being processed right now and the $column is the name of current column.
can( $another_model_method )
$column
Advanced column spec. Should contain one key and one value where key is the plain column name and the value is the HashRef which will be interpreted as column modifiers.
Example:
some_type => [ 'id', { column => \%modifiers } ]
Column modifiers could be:
A CodeRef which will be called in order to check whether the column needs to be processed, or needs to be skipped. Should return boolean value.
constraint => sub { my ( $view_instance, $object_being_processed, $service_args ) = @_; return ( int( rand( 2 ) ) == 1 ); }
$service_args is the returning value of view's service's args method.
$service_args
args
A boolean value.
By default, the view will try to calculate a value for current column using probably light model's method which name is generated like this:
sprintf( '__%s', $type )
Then the view will use this value in couple with the column's name and a few other parameters to produce some unique key.
Then the view will check its cache using Salvation::Service::View::SimpleCache and if there is a value - this value will be used immediately as the column's value, skipping all the calculations described above.
But if the cache has no value for the key - this value will appear in the cache after all further calculations will be done, and will be reused if there will be a request to do the same calculations.
So yes, if the nocache modifier is set to true - there will be no cache usage for such column.
nocache
A boolean value. If set to true, the column will not be included in the output if it has the value equivalent to PERL's false. Default value is false.
As the opposite of skip_false, sticky guarantees that the column will be included in the output even if it's value is equivalent to PERL's false and skip_false is set to true.
skip_false
sticky
If the key sticky exists in column modifiers list - it is true, otherwise it is false.
It will be executed for every object which is being processed with following arguments:
Current view's instance.
An object being processed.
Returning value of view's service's args method.
Returning value should be a HashRef containing arguments to the new method of Salvation::Service::View::Stack::Frame.
new
To install Salvation, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Salvation
CPAN shell
perl -MCPAN -e shell install Salvation
For more information on module installation, please visit the detailed CPAN module installation guide.