package App::Clifton::Service;

use aliased 'App::Clifton::Task';
use Moo;

extends 'App::Clifton::Component';

sub _do {
  my ($self, $do, $args) = @_;
  my $body = do {
    my $body_call = $self->_capture_weakself("_body_for_${do}");
    sub { $body_call->(@_) }
  };
  my @guard = do {
    if ($self->can("_guard_for_${do}")) {
      my $guard_call = $self->_capture_weakself("_guard_for_${do}");
      (guard => sub { $guard_call->(@_) });
    } else {
      ();
    }
  };
  my $deps = {};
  $args ||= {};
  if (my $dep_call = $self->can("_dependencies_for_${do}")) {
    $deps = $self->$dep_call($args);
  }
  $self->_new_child(Task, {
    name => $do, body => $body, dependencies => $deps, @guard,
    args => $args,
  });
}

1;
