1 package App::Rgit::Policy::Interactive;
8 use App::Rgit::Utils qw/:codes/;
10 use base qw/App::Rgit::Policy/;
14 App::Rgit::Policy::Interactive - A policy that asks what to do on error.
22 our $VERSION = '0.06';
24 my ($int_code, $shell);
28 $class = ref $class || $class;
30 eval "require Term::ReadKey"
31 or die "You have to install Term::ReadKey to use the interactive mode.\n";
33 unless (defined $int_code) {
34 $int_code = { Term::ReadKey::GetControlChars() }->{INTERRUPT};
37 unless (defined $shell) {
38 for (grep defined, $ENV{SHELL}, '/bin/sh') {
46 $class->SUPER::new(@_);
50 'a' => [ LAST, 'aborting' ],
51 'i' => [ NEXT, 'ignoring' ],
52 'I' => [ NEXT | SAVE, 'ignoring all' ],
53 'r' => [ REDO, 'retrying' ],
57 my ($policy, $cmd, $conf, $repo, $status, $signal) = @_;
59 return NEXT unless $status;
62 $conf->warn("[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?");
64 Term::ReadKey::ReadMode(4);
65 my $key = Term::ReadKey::ReadKey(0);
66 Term::ReadKey::ReadMode(1);
70 next unless defined $key;
72 if ($key eq $int_code) {
73 $conf->warn("Interrupted, aborting\n");
75 } elsif ($key eq 's') {
77 $conf->info('Opening shell in ', $repo->work, "\n");
80 system { $shell } $shell;
83 $conf->err("Couldn't find any shell\n");
85 } elsif (exists $codes{$key}) {
86 my $code = $codes{$key};
87 $conf->info('Okay, ', $code->[1], "\n");
99 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
101 You can contact me by mail or on C<irc.perl.org> (vincent).
105 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>.
106 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
110 You can find documentation for this module with the perldoc command.
112 perldoc App::Rgit::Policy::Interactive
114 =head1 COPYRIGHT & LICENSE
116 Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
118 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
122 1; # End of App::Rgit::Policy::Interactive