basically operating chain code
[scpubgit/Clifton.git] / lib / App / Clifton / Service.pm
index 043e877..49bb786 100644 (file)
@@ -6,17 +6,26 @@ use Moo;
 extends 'App::Clifton::Component';
 
 sub _do {
-  my ($self, $do, @args) = @_;
+  my ($self, $do, $args) = @_;
   my $body = do {
     my $body_call = $self->_capture_weakself("_body_for_${do}");
-    sub { $body_call->(@args, @_) }
+    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 = {};
   if (my $dep_call = $self->can("_dependencies_for_${do}")) {
-    $deps = $self->$dep_call(@args);
+    $deps = $self->$dep_call($args);
   }
   $self->_new_child(Task, {
-    name => $do, body => $body, dependencies => $deps
+    name => $do, body => $body, dependencies => $deps, @guard,
+    args => $args,
   });
 }