basically operating chain code
[scpubgit/Clifton.git] / lib / App / Clifton / Service.pm
1 package App::Clifton::Service;
2
3 use aliased 'App::Clifton::Task';
4 use Moo;
5
6 extends 'App::Clifton::Component';
7
8 sub _do {
9   my ($self, $do, $args) = @_;
10   my $body = do {
11     my $body_call = $self->_capture_weakself("_body_for_${do}");
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     }
21   };
22   my $deps = {};
23   if (my $dep_call = $self->can("_dependencies_for_${do}")) {
24     $deps = $self->$dep_call($args);
25   }
26   $self->_new_child(Task, {
27     name => $do, body => $body, dependencies => $deps, @guard,
28     args => $args,
29   });
30 }
31
32 1;