don't screw up on messages with no target_name in hints
[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   $args ||= {};
24   if (my $dep_call = $self->can("_dependencies_for_${do}")) {
25     $deps = $self->$dep_call($args);
26   }
27   $self->_new_child(Task, {
28     name => $do, body => $body, dependencies => $deps, @guard,
29     args => $args,
30   });
31 }
32
33 1;