blib/lib/PANT/Cvs.pm

filter: Statementstmt 92.3% 72 / 78 Branchbran 59.0% 13 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 87.1% 102 / 117 CC 15 SCAR 17.0
CC
15
Cov
85%
Run
12.0
HasUpdate
3.0
HasLocalMod
3.0
CRAP 5.5
« blib/lib/PANT/Svn.pm ↑ Summary blib/lib/PANT/Zip.pm »
1 # PANT::Cvs - Provide support for CVS operations
2
3 package PANT::Cvs;
4
5 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 1 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 1 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
23
24 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25
26 1 our @EXPORT = qw( );
27
28 1 our $VERSION = '0.02';
29
30
31 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
32 1 my($clsname, $writer, @rest) =@_;
33 1 my $self = {
34 writer=>$writer,
35 @rest,
36 };
37 1 bless $self, $clsname;
38 1 return $self;
39 }
40
41 3 ▶sub Run {
Subroutine Run: called CC=9 SCAR=24.8
Pod documented
42 3 my($self, $cmd, %args) = @_;
43 3 my $writer = $self->{writer};
44 3 my $cdir = ".";
45 3 ▶ if ($args{directory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"directory"}) 0 3 3
46 0 $cdir = getcwd;
47 0 ▶ chdir($args{directory}) || Abort("Can't change to directory $args{directory}");
Branch: 1 branch
BranchTrueFalseTotal
chdir $args{"directory"} or Abort(qq[Can't change to directory $args{"directory"}]) 0 0 0
48
49 }
50 3 $writer->startTag('li');
51 3 $writer->characters("Run $cmd\n");
52 3 my $output;
53 my $retval;
54 3 ▶ if ($self->{dryrun}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dryrun'}) { } 0 3 3
55 0 $output = "Output of the command $cmd would be here";
56 0 $retval = 1;
57 }
58 else {
59 3 $writer->startTag('pre');
60 3 $cmd .= " 2>&1"; # collect stderr too
61 3 $self->{lines} = [];
62 3 ▶ if (open(PIPE, "$cmd |")) {
Branch: 1 branch
BranchTrueFalseTotal
if (open PIPE, "$cmd |") { } 3 0 3
63 3 ▶ while(my $line = <PIPE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline PIPE)) 20 3 23
64 20 $writer->characters($line);
65 20 push(@ {$self->{lines} }, $line);
66 }
67 3 close(PIPE);
68 3 $retval = $? == 0;
69 }
70 else {
71 0 $retval = 0;
72 }
73 3 $writer->endTag('pre');
74 }
75 3 ▶ $writer->characters("$cmd failed: $!") if ($retval == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $retval == 0 0 3 3
76 3 $writer->endTag('li');
77 0 ▶ do { chdir($cdir) || Abort("Can't change back to $cdir: $!"); } if ($args{directory});
Branch: 2 branches
BranchTrueFalseTotal
if ($args{"directory"}) 0 3 3
chdir $cdir or Abort("Can't change back to ${cdir}: $!") 0 0 0
78 3 return $retval;
79 }
80
81 3 ▶sub HasUpdate {
Subroutine HasUpdate: called CC=3 SCAR=11.0
Pod documented
82 3 my $self = shift;
83 3 foreach my $line (@{ $self->{lines} }) {
84 11 ▶ if ($line =~ /^\s*[UP]\s+/) { # Its a change, one out, all out.
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*[UP]\s+/) 1 10 11
85 1 return 1;
86 }
87 }
88 2 return 0;
89 }
90
91 3 ▶sub HasLocalMod {
Subroutine HasLocalMod: called CC=3 SCAR=11.0
Pod documented
92 3 my $self = shift;
93 3 foreach my $line (@{ $self->{lines} }) {
94 16 ▶ if ($line =~ /^\s*[MA]\s+/) { # Its a change, one out, all out.
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*[MA]\s+/) 1 15 16
95 1 return 1;
96 }
97 }
98 2 return 0;
99 }
100 3 ▶sub HasConflict {
Subroutine HasConflict: called CC=3 SCAR=11.0
Pod documented
101 3 my $self = shift;
102 3 foreach my $line (@{ $self->{lines} }) {
103 16 ▶ if ($line =~ /^\s*[C]\s+/) { # Its a conflict
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*[C]\s+/) 1 15 16
104 1 return 1;
105 }
106 }
107 2 return 0;
108 }
109
110 1 1;
111 __END__
« blib/lib/PANT/Svn.pm ↑ Summary blib/lib/PANT/Zip.pm »