NAME
Salvation::System - Base class for a system
SYNOPSIS
package YourSystem;
use Moose;
extends 'Salvation::System';
no Moose;
REQUIRES
DESCRIPTION
Applied roles
Salvation::Roles::SharedStorage
METHODS
To be called
start
$system_instance -> start();
A method which really starts the system and returns the output of the whole process.
stop
$self -> stop();
A method which interrupts the system immediately.
run_service
$self -> run_service( $absolute_package_name );
$self -> run_service( $absolute_package_name, @service_constructor_args );
A method which runs the full cycle of the given service and returns appropriate Salvation::Service::State if run was successfull.
Service
$self -> Service( $relative_package_name );
$self -> Service( $relative_package_name, \%flags );
Add a service with $name
to the list of system's services.
You can use \%flags
to do some tweaking providing following keys:
- transform_name
-
A CodeRef which will be called in order to change service's name.
transform_name => sub { my ( $system_instance, $service_name ) = @_; $service_name =~ s/MattSmith/DavidTennant/g; return $service_name; }
Useful when you feel especially crutchy.
- constraint
-
A CodeRef which will be called in order to check whether the service needs to be run, or not. Should return boolean value.
constraint => sub { my ( $system_instance, $service_name ) = @_; return ( int( rand( 2 ) ) == 1 ); }
Fatal
$self -> Fatal( @anything );
Add @anything
to the list of fatal errors. The thing will die
with this list in the end.
To be redefined
You can redefine following methods to achieve your own goals.
main
Very first method to be executed in the execution flow. The only argument is $self
which is current system's instance.
output
A method which is responsible for generating final system's output. Its return value is the return value of Salvation::System::start
.
Arguments
$self
-
Current system's instance.
$states
-
An ArrayRef of HashRefs. Each HashRef has following keys:
- service
-
Service's package name.
- state
-
Salvation::Service::State object instance.
- op
-
Salvation::Service::OutputProcessor object instance. It is not present if the service hasn't defined an output processor.
on_hook_load_error
Triggerred by Salvation::Service when it fails to load hook.
Arguments
on_node_rendering_error
Triggerred by Salvation::Service::View when it fails to execute any model's method during process_node
.
Arguments
on_service_controller_method_error
Triggerred by Salvation::Service when it fails to run scheduled controller method.
Arguments
on_service_error
Triggerred by Salvation::System when it fails to run the service.
Arguments
on_service_rerun
Triggerred by Salvation::System when it is about to rerun the service without hooks.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- service
-
Service's package name.
on_service_shared_storage_get
Triggerred by Salvation::SharedStorage when it is about to call its get
and the owner of storage is Salvation::Service.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- key
-
Storage key name.
- service
-
Service's package name.
- instance
-
Service's instance.
on_service_shared_storage_put
Triggerred by Salvation::SharedStorage when it is about to call its put
and the owner of storage is Salvation::Service.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- key
-
Storage key name.
- value
-
A value which is about to be stored.
- service
-
Service's package name.
- instance
-
Service's instance.
on_service_shared_storage_receives_error_notification
Triggerred by Salvation::SharedStorage when it is about to call its put
with the key equal to '$@' and the owner of storage is Salvation::Service.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- data
-
A value which is about to be stored.
- service
-
Service's package name.
- instance
-
Service's instance.
on_service_thrown_error
Triggerred by Salvation::System when the service has been interrupted and service's storage has a key named '$@'.
Arguments
on_shared_storage_get
Triggerred by Salvation::SharedStorage when it is about to call its get
and the owner of storage is Salvation::System.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- key
-
Storage key name.
on_shared_storage_put
Triggerred by Salvation::SharedStorage when it is about to call its put
and the owner of storage is Salvation::System.
Arguments
$self
-
Current system's instance.
$data
-
A HashRef with error data. The keys are:
- key
-
Storage key name.
- value
-
A value which is about to be stored.
on_shared_storage_receives_error_notification
Triggerred by Salvation::SharedStorage when it is about to call its put
with the key equal to '$@' and the owner of storage is Salvation::System.
Arguments