basically operating chain code
[scpubgit/Clifton.git] / lib / App / Clifton / Service.pm
CommitLineData
20038dd8 1package App::Clifton::Service;
2
3use aliased 'App::Clifton::Task';
4use Moo;
5
6extends 'App::Clifton::Component';
7
8sub _do {
327a4b1a 9 my ($self, $do, $args) = @_;
20038dd8 10 my $body = do {
11 my $body_call = $self->_capture_weakself("_body_for_${do}");
327a4b1a 12 sub { $body_call->(@_) }
13 };
14 my @guard = do {
15 if ($self->can("_guard_for_${do}")) {
16 my $guard_call = $self->_capture_weakself("_guard_for_${do}");
17 (guard => sub { $guard_call->(@_) });
18 } else {
19 ();
20 }
20038dd8 21 };
22 my $deps = {};
23 if (my $dep_call = $self->can("_dependencies_for_${do}")) {
327a4b1a 24 $deps = $self->$dep_call($args);
20038dd8 25 }
26 $self->_new_child(Task, {
327a4b1a 27 name => $do, body => $body, dependencies => $deps, @guard,
28 args => $args,
20038dd8 29 });
30}
31
321;