NAME

Salvation::System - Base class for a system

SYNOPSIS

package YourSystem;

use Moose;

extends 'Salvation::System';

no Moose;

REQUIRES

Carp

Moose

DESCRIPTION

Applied roles

Salvation::Roles::SharedStorage

Salvation::Roles::AppArgs

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

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

$@

Containts an error as it has been passed to die.

hook

Hook's package name.

service

Service's package name.

instance

Service's instance.

on_node_rendering_error

Triggerred by Salvation::Service::View when it fails to execute any model's method during process_node.

Arguments

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

$@

Containts an error as it has been passed to die.

spec

A HashRef telling how and which method has been called.

The keys are:

name

Method name.

args

An ArrayRef with method's arguments.

view

View's package name.

instance

View's instance.

on_service_controller_method_error

Triggerred by Salvation::Service when it fails to run scheduled controller method.

Arguments

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

$@

Containts an error as it has been passed to die.

method

Method name.

service

Service's package name.

instance

Service's instance.

on_service_error

Triggerred by Salvation::System when it fails to run the service.

Arguments

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

$@

Containts an error as it has been passed to die.

service

Service's package name.

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

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

$@

Containts an error as it has been passed to Salvation::SharedStorage::put.

service

Service's package name.

instance

Service's instance.

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

$self

Current system's instance.

$data

A HashRef with error data. The keys are:

data

A value which is about to be stored.