]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - lib/App/Rgit/Command.pm
Allow user-defined policies. Enable interactive failure handling when Term::ReadKey...
[perl/modules/rgit.git] / lib / App / Rgit / Command.pm
index 026c73a7047a2082bda40a3f52a9b81dc14a7381..f2f043bd05b0b65aed70e2a0607e9515a7e65268 100644 (file)
@@ -5,9 +5,9 @@ use warnings;
 
 use Carp qw/croak/;
 
-use Object::Tiny qw/cmd args/;
+use Object::Tiny qw/cmd args policy/;
 
-use App::Rgit::Utils qw/validate/;
+use App::Rgit::Utils qw/validate :codes/;
 
 =head1 NAME
 
@@ -51,8 +51,9 @@ sub new {
  }
  eval "require $action; 1" or croak "Couldn't load $action: $@";
  $class->SUPER::new(
-  cmd  => $cmd,
-  args => $args{args} || [ ],
+  cmd    => $cmd,
+  args   => $args{args} || [ ],
+  policy => $args{policy},
  );
 }
 
@@ -77,10 +78,24 @@ sub action {
  $commands{$cmd} = $pkg;
 }
 
+=head2 C<report $conf, $repo, $status>
+
+=cut
+
+sub report {
+ my ($self) = @_;
+ my $cb = $self->policy;
+ return NEXT | SAVE unless $cb;
+ my $code = $cb->(@_);
+ return defined $code ? $code : NEXT;
+}
+
 =head2 C<cmd>
 
 =head2 C<args>
 
+=head2 C<policy>
+
 Accessors.
 
 =head2 C<run $conf>