Gennadiy Filatov

NAME

Salvation::Service::Hook - Base class for a hook

SYNOPSIS

 package YourSystem::Services::SomeService::Hooks::SomeType::SomeValue;

 use Moose;

 extends 'Salvation::Service::Hook';

 no Moose;

REQUIRES

Moose

DESCRIPTION

A special object used to override service's behaviour.

If the service has the hook and the hook has one or more things which can override service's original ones - hook ones will be used.

In example, if service S has its own view (S::Defaults::V) and model (S::Defaults::M), and uses a hook right now (S::Hooks::ExampleType::ExampleValue) which on its own has only a view (S::Hooks::ExampleType::ExampleValue::Defaults::V) then S will use S::Defaults::M as the model and S::Hooks::ExampleType::ExampleValue::Defaults::V as the view. This could be done with view, model, countroller and output processor. DataSet is unhookable.

Also you can define init and main methods for your hook to override service's ones (which are still accessible via SUPER::).

A hook can Call and Hook too, as it is just a subclass of a service. The second gives you an ability to create chained hooks.

In addition to previous example, let's imagine that S::Hooks::ExampleType::ExampleValue uses its own hook right now, say it is S::Hooks::ExampleType::ExampleValue::Hooks::ExampleType2::ExampleValue2 which has a controller (S::Hooks::ExampleType::ExampleValue::Hooks::ExampleType2::ExampleValue2::Defaults::C). Then the service's contoller will be S::Hooks::ExampleType::ExampleValue::Hooks::ExampleType2::ExampleValue2::Defaults::C instead of possible S::Hooks::ExampleType::ExampleValue::Defaults::C or its original S::Defaults::C if it had any.

To define a hook, two things should be done:

1. Hook spec should be added via Salvation::Service::Hook call;
2. Hook package should be present inside your project's directory.

Subclass of

Salvation::Service