File Coverage

lib/Git/Demo/Action/Git.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 6 0.0
condition n/a
subroutine 3 7 42.8
pod 0 3 0.0
total 12 53 22.6


line stmt bran cond sub pod time code
1             package Git::Demo::Action::Git;
2 1     1   4 use strict;
  1         2  
  1         24  
3 1     1   4 use warnings;
  1         2  
  1         18  
4 1     1   4 use File::Spec::Functions;
  1         1  
  1         426  
5              
6             sub new{
7 0     0 0   my $class = shift;
8 0           my $args = shift;
9              
10 0           my $self = {};
11 0           my $logger = Log::Log4perl->get_logger( __PACKAGE__ );
12 0           $self->{logger} = $logger;
13              
14 0           bless $self, $class;
15 0           return $self;
16             }
17              
18             sub run{
19 0     0 0   my( $self, $character, $event ) = @_;
20              
21             # Git output is slung to warn... catch and deal with warnings a bit better!
22             local $SIG{__WARN__} = sub
23             {
24 0     0     foreach( @_ ){
25             # Stupidly, not all Git output goes to output... some goes to warnings...
26 0           print "Git WARN: $_\n";
27             }
28             # Allow a repeat
29 0 0         if( pause() ){
30 0           return $self->run( $character, $event );
31             }
32 0           };
33              
34 0           my $git = $character->git();
35 0           my @cmd = $event->action();
36 0           push( @cmd, @{ $event->args() } );
  0            
37 0           $self->{logger}->info( sprintf( "Git (%s): git %s", $character->name(), join( ' ', @cmd ) ) );
38 0           my $rtn = $git->run( @cmd );
39 0 0         if( $rtn !~ m/^\s*$/ ){
40 0           $rtn .= "\n";
41             }
42 0           return $rtn;
43             }
44              
45             sub pause{
46 0     0 0   print "Repeat (r) or Continue ([enter])?";
47 0           my $in = ;
48 0           chomp( $in );
49 0 0         if( lc( $in ) eq 'r' ){
50 0           return 1;
51             }
52 0           return undef;
53             }
54              
55             1;