The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Salvation::Service - Base class for a service

SYNOPSIS

 package YourSystem::Services::SomeService;

 use Moose;

 extends 'Salvation::Service';

 no Moose;

REQUIRES

Digest::MD5

Moose

DESCRIPTION

Applied roles

Salvation::Roles::AppArgs

Salvation::Roles::DataSet

Salvation::Roles::SharedStorage

Salvation::Roles::SystemReference

Salvation::Roles::ServiceState

METHODS

To be called

system

 $service -> system()

Return appropriate Salvation::System-derived object instance.

model

 $service -> model();

Return appropriate Salvation::Service::Model-derived object instance.

view

 $service -> view();

Return appropriate Salvation::Service::View-derived object instance.

controller

 $service -> controller();

Return appropriate Salvation::Service::Controller-derived object instance.

output_processor

 $service -> output_processor();

Return appropriate Salvation::Service::OutputProcessor-derived object instance.

hook

 $service -> hook();

Return appropriate Salvation::Service::Hook-derived object instance. Normally you should not want to call this method directly.

Call

 $self -> Call( $name );
 $self -> Call( $name, \%flags );

Add a method with $name to the list of controller methods. Each and every method from this list will be called at appropriate stage of the execution flow.

You can use \%flags to do some tweaking providing following keys:

transform_method

A CodeRef which will be called in order to change method's name.

 transform_method => sub
 {
        my ( $service_instance, $method_name ) = @_;

        $method_name = 'A' if $method_name eq 'B';

        return $method_name;
 }

Useful when you feel especially crutchy.

constraint

A CodeRef which will be called in order to check whether the method needs to be called, or not. Should return boolean value.

 constraint => sub
 {
        my ( $service_instance, $method_name ) = @_;

        return ( int( rand( 2 ) ) == 1 );
 }
args

An ArrayRef of method arguments.

fatal

A boolean value. When this value is true and the method fails - the service will be interrupted.

Hook

 $self -> Hook( [ $value, $type ], ... );
 $self -> Hook( [ $value, $type, \%flags ], ... );

Adds a hook spec to the list.

Hook name will be generated somehow like this:

 sprintf(
        '%s::Hooks::%s::%s',
        ref( $self ),
        $type,
        $value
 )

You can use \%flags to do some tweaking providing following keys:

transform_value

A CodeRef which will be called in order to change $value.

 transform_value => sub
 {
        my ( $service_instance, $value, $type ) = @_;

        $value = not $value if $type eq not $type;

        return $value;
 }
transform_type

A CodeRef which will be called in order to change $type.

 transform_type => sub
 {
        my ( $service_instance, $value, $type ) = @_;

        $type = 'Generic' if $type eq 'Specific';

        return $type;
 }
transform_value_and_type

A CodeRef which will be called in order to change both $value and $type.

 transform_value_and_type => sub
 {
        my ( $service_instance, $value, $type ) = @_;

        $value ^= ( $type ^= ( $value ^= $type ) );

        return ( $value, $type );
 }

Because why not?

constraint

A CodeRef which will be called in order to check whether the hook needs to be used, or not. Should return boolean value.

 constraint => sub
 {
        my ( $service_instance, $value, $type ) = @_;

        return ( int( rand( 2 ) ) == 1 );
 }

intent

 $self -> intent( $full_package_name );

Returns new Salvation::Service::Intent object intended to run $full_package_name service within the same environment and with the same DataSet as current service.

throw

 $self -> throw( @anything );

Throws an error which is the \@anything (yes, it will be ArrayRef) to the internals of Salvation and interrupts the service.

start

 $service_instance -> start();

A method which really starts the service and returns the output of the whole process. Normally you should not want to call this method directly as your have Salvation::System::run_service and Salvation::Service::Intent::start.

To be redefined

You can redefine following methods to achieve your own goals.

RERUN_ON_BAD_HOOK

Should return boolean value. Tells the system whether service should be rerun without any hooks on failure, or not. The only argument is $self which is current service's instance. Default value is true.

cacheid

init

A method which semantics tells that it should contain custom initialziation routines, if any is needed. The only argument is $self which is current service's instance.

main

A method which semantics tells that it should contain custom code which is kind of essential for the whole service and should be executed every time. Normally it is sufficient to move such things to controller and schedule calls via Call. The only argument is $self which is current service's instance.