File Coverage

blib/lib/App/Rgit/Policy/Interactive.pm
Criterion Covered Total %
statement 15 49 30.6
branch 0 20 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 81 27.1


line stmt bran cond sub pod time code
1             package App::Rgit::Policy::Interactive;
2              
3 1     1   929 use strict;
  1         2  
  1         33  
4 1     1   5 use warnings;
  1         2  
  1         21  
5              
6 1     1   4 use Cwd ();
  1         2  
  1         16  
7              
8 1     1   5 use App::Rgit::Utils qw/:codes/;
  1         1  
  1         113  
9              
10 1     1   4 use base qw/App::Rgit::Policy/;
  1         9  
  1         620  
11              
12             =head1 NAME
13              
14             App::Rgit::Policy::Interactive - A policy that asks what to do on error.
15              
16             =head1 VERSION
17              
18             Version 0.08
19              
20             =cut
21              
22             our $VERSION = '0.08';
23              
24             =head1 DESCRIPTION
25              
26             When a run exited with non-zero status, this policy asks the user whether he wants to ignore and continue with the next repository, ignore all future possible errors, retry this run or open a shell in the current repository.
27             In this last case, the user will be asked again what to do when he will close the shell.
28              
29             =head1 METHODS
30              
31             This class inherits from L.
32              
33             It implements :
34              
35             =head2 C
36              
37             The constructor will die if L can't be loaded.
38              
39             =cut
40              
41             my ($int_code, $shell);
42              
43             sub new {
44 0     0 1   my $class = shift;
45 0   0       $class = ref $class || $class;
46              
47 0 0         eval "require Term::ReadKey"
48             or die "You have to install Term::ReadKey to use the interactive mode.\n";
49              
50 0 0         unless (defined $int_code) {
51 0           $int_code = { Term::ReadKey::GetControlChars() }->{INTERRUPT};
52             }
53              
54 0 0         unless (defined $shell) {
55 0           for (grep defined, $ENV{SHELL}, '/bin/sh') {
56 0 0         if (-x $_) {
57 0           $shell = $_;
58 0           last;
59             }
60             }
61             }
62              
63 0           $class->SUPER::new(@_);
64             }
65              
66             =head2 C
67              
68             =cut
69              
70             my %codes = (
71             'a' => [ LAST, 'aborting' ],
72             'i' => [ NEXT, 'ignoring' ],
73             'I' => [ NEXT | SAVE, 'ignoring all' ],
74             'r' => [ REDO, 'retrying' ],
75             );
76              
77             sub handle {
78 0     0 1   my ($policy, $cmd, $conf, $repo, $status, $signal) = @_;
79              
80 0 0         return NEXT unless $status;
81              
82 0           while (1) {
83 0           $conf->warn("[a]bort, [i]gnore, [I]gnore all, [r]etry, open [s]hell ?");
84              
85 0           Term::ReadKey::ReadMode(4);
86 0           my $key = Term::ReadKey::ReadKey(0);
87 0           Term::ReadKey::ReadMode(1);
88              
89 0           $conf->warn("\n");
90              
91 0 0         next unless defined $key;
92              
93 0 0         if ($key eq $int_code) {
    0          
    0          
94 0           $conf->warn("Interrupted, aborting\n");
95 0           return LAST;
96             } elsif ($key eq 's') {
97 0 0         if (defined $shell) {
98 0           $conf->info('Opening shell in ', $repo->work, "\n");
99 0           my $cwd = Cwd::cwd;
100 0           $repo->chdir;
101 0           system { $shell } $shell;
  0            
102 0           chdir $cwd;
103             } else {
104 0           $conf->err("Couldn't find any shell\n");
105             }
106             } elsif (exists $codes{$key}) {
107 0           my $code = $codes{$key};
108 0           $conf->info('Okay, ', $code->[1], "\n");
109 0           return $code->[0];
110             }
111             }
112             }
113              
114             =head1 SEE ALSO
115              
116             L.
117              
118             L.
119              
120             L.
121              
122             =head1 AUTHOR
123              
124             Vincent Pit, C<< >>, L.
125              
126             You can contact me by mail or on C (vincent).
127              
128             =head1 BUGS
129              
130             Please report any bugs or feature requests to C, or through the web interface at L.
131             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
132              
133             =head1 SUPPORT
134              
135             You can find documentation for this module with the perldoc command.
136              
137             perldoc App::Rgit::Policy::Interactive
138              
139             =head1 COPYRIGHT & LICENSE
140              
141             Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
142              
143             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
144              
145             =cut
146              
147             1; # End of App::Rgit::Policy::Interactive