File Coverage

blib/lib/PANT/Cvs.pm
Criterion Covered Total %
statement 66 72 91.6
branch 11 20 55.0
condition n/a
subroutine 12 12 100.0
pod 5 5 100.0
total 94 109 86.2


line stmt bran cond sub pod time code
1             # PANT::Cvs - Provide support for CVS operations
2            
3             package PANT::Cvs;
4            
5 1     1   1651 use 5.008;
  1         4  
  1         42  
6 1     1   6 use strict;
  1         2  
  1         34  
7 1     1   5 use warnings;
  1         2  
  1         29  
8 1     1   5 use Carp;
  1         2  
  1         64  
9 1     1   7 use Cwd;
  1         1  
  1         56  
10 1     1   6 use XML::Writer;
  1         2  
  1         22  
11 1     1   4 use Exporter;
  1         2  
  1         1444  
12            
13             our @ISA = qw(Exporter);
14            
15             # Items to export into callers namespace by default. Note: do not export
16             # names by default without a very good reason. Use EXPORT_OK instead.
17             # Do not simply export all your public functions/methods/constants.
18            
19             # This allows declaration use PANT ':all';
20             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
21             # will save memory.
22             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
23            
24             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25            
26             our @EXPORT = qw( );
27            
28             our $VERSION = '0.02';
29            
30            
31             sub new {
32 1     1 1 3 my($clsname, $writer, @rest) =@_;
33 1         3 my $self = {
34             writer=>$writer,
35             @rest,
36             };
37 1         3 bless $self, $clsname;
38 1         4 return $self;
39             }
40            
41             sub Run {
42 3     3 1 716 my($self, $cmd, %args) = @_;
43 3         8 my $writer = $self->{writer};
44 3         7 my $cdir = ".";
45 3 50       11 if ($args{directory}) {
46 0         0 $cdir = getcwd;
47 0 0       0 chdir($args{directory}) || Abort("Can't change to directory $args{directory}");
48            
49             }
50 3         29 $writer->startTag('li');
51 3         219 $writer->characters("Run $cmd\n");
52 3         76 my $output;
53             my $retval;
54 3 50       11 if ($self->{dryrun}) {
55 0         0 $output = "Output of the command $cmd would be here";
56 0         0 $retval = 1;
57             }
58             else {
59 3         11 $writer->startTag('pre');
60 3         237 $cmd .= " 2>&1"; # collect stderr too
61 3         9 $self->{lines} = [];
62 3 50       18026 if (open(PIPE, "$cmd |")) {
63 3         29102 while(my $line = ) {
64 20         176 $writer->characters($line);
65 20         823 push(@ {$self->{lines} }, $line);
  20         2088  
66             }
67 3         128 close(PIPE);
68 3         175 $retval = $? == 0;
69             }
70             else {
71 0         0 $retval = 0;
72             }
73 3         24 $writer->endTag('pre');
74             }
75 3 50       149 $writer->characters("$cmd failed: $!") if ($retval == 0);
76 3         20 $writer->endTag('li');
77 3 0       87 do { chdir($cdir) || Abort("Can't change back to $cdir: $!"); } if ($args{directory});
  0 50       0  
78 3         104 return $retval;
79             }
80            
81             sub HasUpdate {
82 3     3 1 8 my $self = shift;
83 3         6 foreach my $line (@{ $self->{lines} }) {
  3         21  
84 11 100       50 if ($line =~ /^\s*[UP]\s+/) { # Its a change, one out, all out.
85 1         11 return 1;
86             }
87             }
88 2         26 return 0;
89             }
90            
91             sub HasLocalMod {
92 3     3 1 9 my $self = shift;
93 3         6 foreach my $line (@{ $self->{lines} }) {
  3         20  
94 16 100       56 if ($line =~ /^\s*[MA]\s+/) { # Its a change, one out, all out.
95 1         8 return 1;
96             }
97             }
98 2         18 return 0;
99             }
100             sub HasConflict {
101 3     3 1 6 my $self = shift;
102 3         6 foreach my $line (@{ $self->{lines} }) {
  3         10  
103 16 100       61 if ($line =~ /^\s*[C]\s+/) { # Its a conflict
104 1         10 return 1;
105             }
106             }
107 2         16 return 0;
108             }
109            
110             1;
111             __END__