blib/lib/ClearCase/Argv.pm

filter: Statementstmt 12.5% 72 / 574 Branchbran 2.5% 10 / 400 Conditioncond 2.3% 4 / 168 MC/DCmcdc 0.0% 0 / 97 Subroutinesub 31.2% 15 / 48 Podpod 13.6% 3 / 22 totaltotal 7.9% 104 / 1309 CC 258 SCAR 66.3
CC
258
Cov
8%
qx
2256.0
system
1406.0
_ipc_cmd
1190.0
CRAP 757.4
↑ Summary
1 package ClearCase::Argv;
2  
3 1 $VERSION = '1.54';
4  
5 1 ▶use Argv 1.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use constant MSWIN => $^O =~ /MSWin|Windows_NT/i ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /MSWin|Windows_NT/i ? : 0 1 1
8 1 ▶use constant CYGWIN => $^O =~ /cygwin/i ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /cygwin/i ? : 0 1 1
9  
10 1 my $NUL = MSWIN ? 'NUL' : '/dev/null';
11  
12 1 @ISA = qw(Argv);
13 1 %EXPORT_TAGS = ( 'functional' => [ qw(ctsystem ctexec ctqx ctqv ctpipe chdir) ] );
14 1 @EXPORT_OK = (@{$EXPORT_TAGS{functional}});
15  
16 1 *AUTOLOAD = \&Argv::AUTOLOAD;
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 my $class = __PACKAGE__;
21 1 if (CYGWIN) {
22 require Text::ParseWords;
23 $class->inpathnorm(1);
24 $class->outpathnorm(1);
25 }
26 1 my %pidcount;
27 1 ▶END {
Subroutine END: called CC=1 SCAR=0.0
28 1 my $ret = $?;
29 1 ClearCase::Argv->ipc(0); #Kill any remaining coprocess
30 1 $? |= $ret;
31 }
32 # For programming purposes we can't allow per-user preferences.
33 1 ▶if ($ENV{CLEARCASE_PROFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CLEARCASE_PROFILE"}) 0 1 1
34 0 $ENV{_CLEARCASE_PROFILE} = $ENV{CLEARCASE_PROFILE};
35 0 delete $ENV{CLEARCASE_PROFILE};
36 }
37  
38 # Allow EV's setting class data in the derived class to override the
39 # base class's defaults.There's probably a better way to code this.
40 1 for (grep !/^_/, keys %Argv::Argv) {
41 21 (my $ev = uc(join('_', __PACKAGE__, $_))) =~ s%::%_%g;
42 21 ▶ $Argv::Argv{$_} = $ENV{$ev} if defined $ENV{$ev};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{$ev} 0 21 21
43 }
44  
45 1 my @ct = ('cleartool');
46  
47 # Attempt to find the definitive ClearCase bin path at startup. Don't
48 # try excruciatingly hard, it would take unwarranted time. And don't
49 # do so at all if running setuid or as root. If this doesn't work,
50 # the path can be set explicitly via the 'cleartool_path' class method.
51 1 ▶if (!MSWIN && ($< == 0 || $< != $> || !grep{$_}@ENV{qw(PATH ATRIAHOME)})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($< == 0 or $< != $> or not grep({$_;} @ENV{'PATH', 'ATRIAHOME'})) { } 0 1 1
elsif (not $ENV{'PATH'} =~ /\W(atria|ClearCase)\Wbin\b/i) { } 1 0 1
Condition33%2/6
$< == 0 or $< != $> or not grep({$_;} @ENV{"PATH", "ATRIAHOME"})
l!l&&r!l&&!r
001
$< == 0 or $< != $>
l!l&&r!l&&!r
001
MC/DC0%0/3
$< == 0 or $< != $> or not grep({$_;} @ENV{"PATH", "ATRIAHOME"})
$< == 0 $< != $> not grep({$_;} @ENV{"PATH", "ATRIAHOME"})
Truth table25%1/4
A or B or not(C)
A= $< == 0B= $< != $>C= not grep({$_;} @ENV{"PATH", "ATRIAHOME"})
ABCresult
1XX1
01X1
0011
0000
52 # running as root, or setuid, even if the same user as the suid one...
53 0 @ct = ('/opt/rational/clearcase/bin/cleartool');
54 } elsif ($ENV{PATH} !~ m%\W(atria|ClearCase)\Wbin\b%i) {
55 1 if (!MSWIN) {
56 1 ▶ my $abin = $ENV{ATRIAHOME} ? "$ENV{ATRIAHOME}/bin" : '/usr/atria/bin';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'ATRIAHOME'} ? : 0 1 1
57 1 ▶ $ENV{PATH} .= ":$abin" if -d $abin && $ENV{PATH} !~ m%/atria/bin%;
Branch: 1 branch
BranchTrueFalseTotal
if -d $abin and not $ENV{"PATH"} =~ m[/atria/bin] 0 1 1
Condition33%1/3
-d $abin and not $ENV{"PATH"} =~ m[/atria/bin]
!ll&&!rl&&r
100
MC/DC0%0/2
-d $abin and not $ENV{"PATH"} =~ m[/atria/bin]
-d $abin not $ENV{"PATH"} =~ m[/atria/bin]
Truth table33%1/3
A and not(B)
A= -d $abinB= not $ENV{"PATH"} =~ m[/atria/bin]
ABresult
0X0
100
111
58 } else {
59 local $^W = 0;
60 for ( ($ENV{ATRIAHOME} || '') . "/bin",
61 'C:/Program Files/Rational/ClearCase/bin',
62 'D:/Program Files/Rational/ClearCase/bin',
63 'C:/atria/bin',
64 'D:/atria/bin') {
65 if (-d $_ && $ENV{PATH} !~ m%$_%) {
66 $ENV{PATH} .= ";$_";
67 last;
68 }
69 }
70 }
71 }
72  
73 # Class method to get/set the location of 'cleartool'.
74 0 ▶sub cleartool_path {
Subroutine cleartool_path: not called CC=5 SCAR=34.0
Pod undocumented
75 0 my $self = shift;
76 0 ▶ if (ref $self and $self->{CT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->{'CT'}) { } 0 0 0
Condition0%0/3
ref $self and $self->{"CT"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and $self->{"CT"}
ref $self $self->{"CT"}
Truth table0%0/3
A and B
A= ref $selfB= $self->{"CT"}
ABresult
0X0
100
111
77 0 ▶ $self->ct(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
78 0 return @{$self->ct};
79 } else {
80 0 ▶ @ct = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
81 0 return @ct;
82 }
83 }
84 1 *find_cleartool = \&cleartool_path; # backward compatibility
85  
86 0 ▶sub perlscript {
Subroutine perlscript: not called CC=4 SCAR=30.0
Pod undocumented
87 0 my $self = shift;
88 0 for (@{$self->{CT}}) {
89 0 ▶ next unless open my $fd, q(<), $_;
Branch: 1 branch
BranchTrueFalseTotal
unless open my $fd, "<", $_ 0 0 0
90 0 my $line = <$fd>;
91 0 close $fd;
92 0 ▶ return 1 if $line =~ m%^(#!|\@rem ).*\bperl\b%i;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^(#!|\@rem ).*\bperl\b/i 0 0 0
93 }
94 0 return 0;
95 }
96 0 ▶sub ct {
Subroutine ct: not called CC=9 SCAR=45.0
Pod undocumented
97 0 my $self = shift;
98 0 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
99 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
100 0 ▶ if ($self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ipc) { } 0 0 0
101 # servicing attrs after raw copy: the pid count was not
102 # incremented yet, so we cannot call ipc(0)
103 0 delete $self->{IPC};
104 0 ▶ $self->{CT} = ref($_[0])? $_[0] : [@_];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
105 0 $self->ipc(1);
106 } else {
107 0 ▶ $self->{CT} = ref($_[0])? $_[0] : [@_];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
108 }
109 0 ▶ $self->{WRAPPER}++ if $self->perlscript;
Branch: 1 branch
BranchTrueFalseTotal
if $self->perlscript 0 0 0
110 0 ▶ return defined(wantarray)? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
111 } else {
112 0 ▶ return $self->{CT}? @{$self->{CT}} : @ct;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'CT'} ? : 0 0 0
113 }
114 } else {
115 0 return cleartool_path;
116 }
117 }
118 # Override of base-class method to change a prog value of 'foo' into
119 # qw(cleartool foo). If the value is already an array or array ref
120 # leave it alone. Same thing if the 1st word contains /cleartool/
121 # or is an absolute path.
122 0 ▶sub prog {
Subroutine prog: not called CC=7 SCAR=40.3
Pod documented
123 0 my $self = shift;
124 0 ▶ return $self->SUPER::prog unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
125 0 my $prg = shift;
126 0 ▶ if (@_ || ref($prg) || $prg =~ m%^/|^\S*(?:clear|multi)tool%
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or ref $prg or $prg =~ m[^/|^\S*(?:clear|multi)tool] or $self->ctcmd) { } 0 0 0
Condition0%0/9
@_ or ref $prg or $prg =~ m[^/|^\S*(?:clear|multi)tool] or $self->ctcmd
l!l&&r!l&&!r
000
@_ or ref $prg or $prg =~ m[^/|^\S*(?:clear|multi)tool]
l!l&&r!l&&!r
000
@_ or ref $prg
l!l&&r!l&&!r
000
MC/DC0%0/4
@_ or ref $prg or $prg =~ m[^/|^\S*(?:clear|multi)tool] or $self->ctcmd
@_ ref $prg $prg =~ m[^/|^\S*(?:clear|multi)tool] $self->ctcmd
Truth table0%0/5
A or B or C or D
A= @_B= ref $prgC= $prg =~ m[^/|^\S*(?:clear|multi)tool]D= $self->ctcmd
ABCDresult
1XXX1
01XX1
001X1
00011
00000
127 || $self->ctcmd) {
128 0 return $self->SUPER::prog($prg, @_);
129 } else {
130 0 require Text::ParseWords;
131 0 ▶ my @prg = map { s/^'(.*)'$/$1/ || s/^"(.*)"$/$1/; $_ }
Branch: 1 branch
BranchTrueFalseTotal
s/^'(.*)'$/$1/ or s/^"(.*)"$/$1/ 0 0 0
132 Text::ParseWords::parse_line('\s+', 1, $prg);
133 0 return $self->SUPER::prog([$self->ct, @prg], @_);
134 }
135 }
136  
137 # Overridden to allow for alternate execution modes.
138 0 ▶sub exec {
Subroutine exec: not called CC=6 SCAR=37.4
Pod undocumented
139 0 ▶ $class->new(@_)->exec if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
140 0 my $self = shift;
141 0 ▶ if ($self->ctcmd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ctcmd) { } 0 0 0
elsif ($self->ipc) { } 0 0 0
142 0 exit $self->system(@_) >> 8;
143 } elsif ($self->ipc) {
144 0 my $rc = $self->system(@_);
145 0 ▶ $rc ||= $self->ipc(0);
Condition0%0/3
$rc ||= $self->ipc(0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc ||= $self->ipc(0)
$rc $self->ipc(0)
Truth table0%0/3
A ||= B
A= $rcB= $self->ipc(0)
ABresult
1X1
011
000
146 0 exit($rc);
147 } else {
148 0 return $self->SUPER::exec(@_);
149 }
150 }
151  
152 # Overridden to allow for alternate execution modes.
153 0 ▶sub system {
Subroutine system: not called CC=37 SCAR=72.5
Pod undocumented
154 0 ▶ return $class->new(@_)->system if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
155 0 my $self = shift;
156 0 my @rargs = @_;
157 0 $self->_cvt_input_cw() if CYGWIN;
158  
159 0 ▶ if (!$self->ctcmd && !$self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ctcmd or $self->ipc) 0 0 0
Condition0%0/3
$self->ctcmd or $self->ipc
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->ctcmd or $self->ipc
$self->ctcmd $self->ipc
Truth table0%0/3
A or B
A= $self->ctcmdB= $self->ipc
ABresult
1X1
011
000
160 0 if (CYGWIN) {
161 my @ret = $self->SUPER::qv(@rargs);
162 $self->unixpath(@ret) unless $self->{WRAPPER};
163 print join("", @ret) if @ret;
164 return $?;
165 } else {
166 0 return $self->SUPER::system(@rargs);
167 }
168 }
169  
170 0 my $envp = $self->envp;
171 0 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
172 0 ▶ $self->args($self->glob) if $self->autoglob;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autoglob 0 0 0
173 0 my @prog = @{$self->{AV_PROG}};
174 0 ▶ shift(@prog) while grep m%(?:clear|multi)tool%, @prog;
Branch: 1 branch
BranchTrueFalseTotal
grep /(?:clear|multi)tool/, @prog and do { shift @prog } 0 0 0
175 0 my @opts = $self->_sets2opts(@_);
176 0 my @args = @{$self->{AV_ARGS}};
177 0 my @cmd = (@prog, @opts, @args);
178 0 my $dbg = $self->dbglevel;
179 0 ▶ $self->_addstats("cleartool @prog", scalar @args) if %Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if %Argv::Summary 0 0 0
180 0 ▶ $self->warning("cannot close stdin of child process") if $ifd;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd 0 0 0
181 0 ▶ if ($self->noexec && !$self->_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noexec and not $self->_read_only) 0 0 0
Condition0%0/3
$self->noexec and not $self->_read_only
!ll&&!rl&&r
000
MC/DC0%0/2
$self->noexec and not $self->_read_only
$self->noexec not $self->_read_only
Truth table0%0/3
A and not(B)
A= $self->noexecB= not $self->_read_only
ABresult
0X0
100
111
182 0 $self->_dbg($dbg, '-', \*STDERR, @cmd);
183 0 return 0;
184 }
185 0 open(_O, '>&STDOUT');
186 0 open(_E, '>&STDERR');
187 0 my($outplace, $errplace) = (0, 0);
188 0 ▶ if ($self->quiet) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->quiet) { } 0 0 0
elsif ($ofd == 2) { } 0 0 0
elsif (not $ofd =~ /^\d*$/) { } 0 0 0
189 0 $outplace = 1;
190 } elsif ($ofd == 2) {
191 0 ▶ open(STDOUT, '>&STDERR') || warn "Can't dup stdout";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&STDERR" or warn "Can't dup stdout" 0 0 0
192 } elsif ($ofd !~ m%^\d*$%) {
193 0 ▶ open(STDOUT, $ofd) || warn "$ofd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, $ofd or warn "${ofd}: $!" 0 0 0
194 } else {
195 0 ▶ warn "Warning: illegal value '$ofd' for stdout" if $ofd > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $ofd > 2 0 0 0
196 0 ▶ if ($ofd == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ofd == 0) 0 0 0
197 0 $outplace = -1;
198 0 ▶ open(STDOUT, ">$NUL") if $self->ipc();
Branch: 1 branch
BranchTrueFalseTotal
if $self->ipc 0 0 0
199 }
200 }
201 0 ▶ $self->_dbg($dbg, '+>', \*STDERR, @cmd) if $dbg && $self->ctcmd;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg and $self->ctcmd 0 0 0
Condition0%0/3
$dbg and $self->ctcmd
!ll&&!rl&&r
000
MC/DC0%0/2
$dbg and $self->ctcmd
$dbg $self->ctcmd
Truth table0%0/3
A and B
A= $dbgB= $self->ctcmd
ABresult
0X0
100
111
202 0 ▶ if ($efd == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($efd == 1) { } 0 0 0
elsif (not $efd =~ /^\d*$/) { } 0 0 0
203 0 ▶ open(STDERR, '>&STDOUT') || warn "Can't dup stderr";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or warn "Can't dup stderr" 0 0 0
204 } elsif ($efd !~ m%^\d*$%) {
205 0 ▶ open(STDERR, $efd) || warn "$efd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, $efd or warn "${efd}: $!" 0 0 0
206 } else {
207 0 ▶ warn "Warning: illegal value '$efd' for stderr" if $efd > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $efd > 2 0 0 0
208 0 ▶ $errplace = -1 if $efd == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $efd == 0 0 0 0
209 }
210 0 my $rc = 0;
211 0 ▶ if ($self->ctcmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ctcmd) { } 0 0 0
212 0 my $ctc = ClearCase::CtCmd->new(outfunc=>$outplace, errfunc=>$errplace);
213 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
214 0 local %ENV = %$envp;
215 0 $ctc->exec(@cmd);
216 } else {
217 0 $ctc->exec(@cmd);
218 }
219 0 $rc = $ctc->status;
220 } else {
221 0 ▶ if ($cmd[0] eq 'setview') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[0] eq "setview") 0 0 0
222 0 ▶ if ($cmd[1] eq '-exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[1] eq "-exec") 0 0 0
223 0 return $self->stderr($efd)->SUPER::system;
224 }
225 0 $self->ipc(0);
226 0 my @data;
227 0 $self->ipc($cmd[1], \@data);
228 0 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 0 0 0
229 0 ▶ if ($efd == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($efd == 2) { } 0 0 0
elsif ($efd == 1) { } 0 0 0
230 0 print STDERR @data;
231 } elsif ($efd == 1) {
232 0 print STDOUT @data;
233 }
234 0 my @err = grep !/^cleartool: Warning:/, @data;
235 0 ▶ delete $self->{IPC} if @err; #dtor would send 'exit' to defunct
Branch: 1 branch
BranchTrueFalseTotal
if @err 0 0 0
236 0 return scalar @err;
237 } else {
238 0 return 0;
239 }
240 }
241 0 $rc = $self->_ipc_cmd(undef, $ofd, $efd, @cmd);
242 }
243 0 open(STDOUT, '>&_O'); close(_O);
244 0 open(STDERR, '>&_E'); close(_E);
245 0 ▶ print STDERR "+ (\$? == $?)\n" if $dbg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg > 1 0 0 0
246 0 ▶ $self->fail($self->syfail) if $rc;
Branch: 1 branch
BranchTrueFalseTotal
if $rc 0 0 0
247 0 $? = $rc;
248 0 return $rc;
249 }
250  
251 # Overridden to allow for alternate execution modes.
252 0 ▶sub qx { # } --for emacs CPerl mode, as 'qx' is a keyword
Subroutine qx: not called CC=47 SCAR=77.2
Pod undocumented
253 0 ▶ return $class->new(@_)->qx if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
254 0 my $self = shift;
255 0 my @rargs = @_;
256 0 $self->_cvt_input_cw() if CYGWIN;
257  
258 0 ▶ unless ($self->ctcmd || $self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ctcmd or $self->ipc) 0 0 0
Condition0%0/3
$self->ctcmd or $self->ipc
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->ctcmd or $self->ipc
$self->ctcmd $self->ipc
Truth table0%0/3
A or B
A= $self->ctcmdB= $self->ipc
ABresult
1X1
011
000
259 0 my @ret = $self->SUPER::qx(@rargs);
260 0 if (CYGWIN and !$self->{WRAPPER}) {
261 $self->unixpath(@ret);
262 }
263 0 ▶ return wantarray? @ret : join '', @ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
264 }
265  
266 0 my($rc, $data, $errors);
267 0 my $dbg = $self->dbglevel;
268  
269 0 my $envp = $self->envp;
270 0 my($ifd, $ofd, $efd) = ($self->stdin, $self->stdout, $self->stderr);
271 0 ▶ $self->args($self->glob) if $self->autoglob;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autoglob 0 0 0
272 0 my @prog = @{$self->{AV_PROG}};
273 0 ▶ shift(@prog) while grep m%(?:clear|multi)tool%, @prog;
Branch: 1 branch
BranchTrueFalseTotal
grep /(?:clear|multi)tool/, @prog and do { shift @prog } 0 0 0
274 0 my @opts = $self->_sets2opts(@_);
275 0 my @args = @{$self->{AV_ARGS}};
276 0 my @cmd = (@prog, @opts, @args);
277 0 ▶ $self->_addstats("cleartool @prog", scalar @args) if %Argv::Summary;
Branch: 1 branch
BranchTrueFalseTotal
if %Argv::Summary 0 0 0
278 0 ▶ $self->warning("cannot close stdin of child process") if $ifd;
Branch: 1 branch
BranchTrueFalseTotal
if $ifd 0 0 0
279 0 ▶ if ($self->noexec && !$self->_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->noexec and not $self->_read_only) 0 0 0
Condition0%0/3
$self->noexec and not $self->_read_only
!ll&&!rl&&r
000
MC/DC0%0/2
$self->noexec and not $self->_read_only
$self->noexec not $self->_read_only
Truth table0%0/3
A and not(B)
A= $self->noexecB= not $self->_read_only
ABresult
0X0
100
111
280 0 $self->_dbg($dbg, '-', \*STDERR, @cmd);
281 0 return 0;
282 }
283 0 ▶ $self->_dbg($dbg, '+>', \*STDERR, @cmd) if $dbg && $self->ctcmd;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg and $self->ctcmd 0 0 0
Condition0%0/3
$dbg and $self->ctcmd
!ll&&!rl&&r
000
MC/DC0%0/2
$dbg and $self->ctcmd
$dbg $self->ctcmd
Truth table0%0/3
A and B
A= $dbgB= $self->ctcmd
ABresult
0X0
100
111
284 0 ▶ if ($self->ctcmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ctcmd) { } 0 0 0
285 0 my $ctc = ClearCase::CtCmd->new;
286 0 ▶ if ($envp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envp) { } 0 0 0
287 0 local %ENV = %$envp;
288 0 ($rc, $data, $errors) = $ctc->exec(@cmd);
289 } else {
290 0 ($rc, $data, $errors) = $ctc->exec(@cmd);
291 }
292 0 ▶ $data ||= '';
Condition0%0/2
$data ||= ""
l!l
00
MC/DC0%0/1
$data ||= ""
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
293 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
294 0 ▶ if (!$ofd) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ofd) { } 0 0 0
elsif ($ofd == 2) { } 0 0 0
295 0 $data = '';
296 } elsif ($ofd == 2) {
297 0 print STDERR $data;
298 }
299 }
300 0 ▶ if ($errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errors) 0 0 0
301 0 ▶ if ($efd == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($efd == 1) { } 0 0 0
elsif ($efd == 2) { } 0 0 0
302 0 $data .= $errors;
303 } elsif ($efd == 2) {
304 0 print STDERR $errors;
305 }
306 }
307 0 ▶ print STDERR "+ (\$? == $?)\n" if $dbg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg > 1 0 0 0
308 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
309 0 my @data = split /\n/, $data;
310 0 ▶ if (! $self->autochomp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->autochomp) 0 0 0
311 0 for (@data) { $_ .= "\n" }
312 }
313 0 $self->unixpath(@data) if MSWIN && $self->outpathnorm;
314 0 ▶ print STDERR map {"+ <- $_"} @data if @data && $dbg >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @data and $dbg >= 2 0 0 0
Condition0%0/3
@data and $dbg >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
@data and $dbg >= 2
@data $dbg >= 2
Truth table0%0/3
A and B
A= @dataB= $dbg >= 2
ABresult
0X0
100
111
315 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
316 0 $self->lastresults($rc, @data);
317 0 $self->fail($self->qxfail);
318 }
319 0 $? = $rc;
320 0 return @data;
321 } else {
322 0 ▶ chomp($data) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
323 0 $self->unixpath($data) if MSWIN && $self->outpathnorm;
324 0 ▶ print STDERR "+ <- $data" if $data && $dbg >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $data and $dbg >= 2 0 0 0
Condition0%0/3
$data and $dbg >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$data and $dbg >= 2
$data $dbg >= 2
Truth table0%0/3
A and B
A= $dataB= $dbg >= 2
ABresult
0X0
100
111
325 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
326 0 $self->lastresults($rc, $data);
327 0 $self->fail($self->qxfail);
328 }
329 0 $? = $rc;
330 0 return $data;
331 }
332 } else {
333 0 ▶ if ($cmd[0] eq 'setview') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[0] eq "setview") 0 0 0
334 0 ▶ if ($cmd[1] eq '-exec') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[1] eq "-exec") 0 0 0
335 0 my $ret = $self->stderr($efd)->SUPER::qx;
336 0 ▶ chomp($ret) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
337 0 ▶ return wantarray? split(/\n/, $ret) : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
338 }
339 0 $self->ipc(0);
340 0 my @data;
341 0 $self->ipc($cmd[1], \@data);
342 0 ▶ if ($efd == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($efd == 2) { } 0 0 0
elsif ($efd == 1) { } 0 0 0
343 0 print STDERR @data;
344 } elsif ($efd == 1) {
345 0 ▶ return wantarray? @data : join '', @data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
346 }
347 0 return '';
348 }
349 0 my @data = ();
350 0 $rc = $self->_ipc_cmd(\@data, $ofd, $efd, @cmd);
351 0 ▶ print STDERR "+ (\$? == $?)\n" if $dbg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg > 1 0 0 0
352 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
353 0 ▶ chomp(@data) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
354 0 $self->unixpath(@data) if MSWIN && $self->outpathnorm;
355 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
356 0 $self->lastresults($rc, @data);
357 0 $self->fail($self->qxfail);
358 }
359 0 $? = $rc;
360 0 return @data;
361 } else {
362 0 my $data = join '', @data;
363 0 ▶ chomp($data) if $self->autochomp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autochomp 0 0 0
364 0 $self->unixpath($data) if MSWIN && $self->outpathnorm;
365 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
366 0 $self->lastresults($rc, $data);
367 0 $self->fail($self->qxfail);
368 }
369 0 $? = $rc;
370 0 return $data;
371 }
372 }
373 }
374  
375 # Overridden to allow special handling for CtCmd and IPC modes.
376 0 ▶sub pipe {
Subroutine pipe: not called CC=9 SCAR=45.0
Pod undocumented
377 0 ▶ return $class->new(@_)->pipe if !ref($_[0]) || ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[0] or ref $_[0] eq "HASH" 0 0 0
Condition0%0/3
not ref $_[0] or ref $_[0] eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_[0] or ref $_[0] eq "HASH"
not ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/3
not(A) or B
A= not ref $_[0]B= ref $_[0] eq "HASH"
ABresult
1X1
011
000
378  
379 0 my $self = shift;
380 0 my $mode;
381 0 ▶ if ($self->ctcmd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ctcmd) { } 0 0 0
elsif ($self->ipc) { } 0 0 0
382 0 $mode = 'CtCmd';
383 } elsif ($self->ipc) {
384 0 $mode = 'IPC';
385 }
386 0 ▶ if ($mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) { } 0 0 0
387 0 my $otherSelf = $self->clone();
388 0 ▶ $self->warning("$mode usage incompatible with pipe - temporarily" .
Branch: 1 branch
BranchTrueFalseTotal
if $self->dbglevel 0 0 0
389 " reverting to plain cleartool") if $self->dbglevel;
390 0 ▶ if ($mode eq 'CtCmd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'CtCmd') { } 0 0 0
391 0 $otherSelf->ctcmd(0);
392 0 my @prg = $otherSelf->prog; #Depends on the exact invocation path
393 0 ▶ $otherSelf->prog($self->ct, @prg)
Branch: 1 branch
BranchTrueFalseTotal
unless grep /(?:clear|multi)tool/, @prg 0 0 0
394 unless grep m%(?:clear|multi)tool%, @prg;
395 } else {
396 0 $otherSelf->ipc(0);
397 }
398 0 return $otherSelf->SUPER::pipe(@_);
399 } else {
400 0 return $self->SUPER::pipe(@_);
401 }
402 }
403  
404 # Normalizes a path to Unix style (forward slashes).
405 0 ▶sub unixpath {
Subroutine unixpath: not called CC=4 SCAR=24.6
Pod undocumented
406 0 my $self = shift;
407 0 if (CYGWIN) {
408 1 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
409 for my $line (@_) {
410 my $nl = chomp $line;
411 my $bs = $line =~ s/\\$//;
412 $line =~ s%\r$%%;
413 my @chars = split//,$line;
414 my $odd = (((grep/'/,@chars) % 2) || ((grep/"/,@chars) % 2));
415 my @bit = $odd? split/(\s+)/,$line
416 : Text::ParseWords::parse_line('\s+', 'delimiters', $line);
417 map {
418 s%\\%/%g if m%(?:^(?:"|[\w/.-]*)|\@)\\%;
419 if (m%^(vob|[A-Za-z]):%) {
420 $_ = Cygwin::win_to_posix_path($_);
421 } else {
422 s%^//view%/view%;
423 }
424 } grep { $_ && m%\S% } @bit;
425 $line = join '', grep {defined($_)} @bit;
426 $line .= '\\' if $bs;
427 $line .= "\n" if $nl;
428 }
429 } else {
430 0 $self->SUPER::unixpath(@_);
431 # Now apply CC-specific, @@-sensitive transforms to partial lines.
432 0 for my $line (@_) {
433 0 my $fixed = '';
434 0 for (split(m%(\S+@@\S*)%, $line)) {
435 0 ▶ s%\\%/%g if m%^.*?\S+@@%;
Branch: 1 branch
BranchTrueFalseTotal
if /^.*?\S+\@@/ 0 0 0
436 0 $fixed .= $_;
437 }
438 0 $line = $fixed;
439 }
440 }
441 }
442  
443 # Attaches to or detaches from a CtCmd object for execution.
444 0 ▶sub ctcmd {
Subroutine ctcmd: not called CC=24 SCAR=62.0
Pod undocumented
445 0 my $self = shift; # this might be an instance or a classname
446 0 my $level = shift;
447 0 ▶ $level = 2 if !defined($level) && !defined(wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $level or defined wantarray 0 0 0
Condition0%0/3
defined $level or defined wantarray
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $level or defined wantarray
defined $level defined wantarray
Truth table0%0/3
A or B
A= defined $levelB= defined wantarray
ABresult
1X1
011
000
448 0 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 0 0 0
449 0 ▶ if ($self->ipc && !CYGWIN) {
Branch: 1 branch
BranchTrueFalseTotal
if () 0 0 0
Condition0%0/2
$self->ipc and
!ll
00
MC/DC0%0/1
$self->ipc and
$self->ipc
Truth table0%0/2
A
A= $self->ipc
Aresult
00
11
450 0 $self->ipc(0); # shut the ipc down
451 }
452 0 eval { require ClearCase::CtCmd };
453 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
454 0 my $msg = $@;
455 0 ▶ if ($level == 2 && $msg =~ m%^(Can't locate \S+)%) {
Branch: 2 branches
BranchTrueFalseTotal
if ($level == 2 and $msg =~ /^(Can't locate \S+)/) { } 0 0 0
elsif ($level > 2) { } 0 0 0
Condition0%0/3
$level == 2 and $msg =~ /^(Can't locate \S+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$level == 2 and $msg =~ /^(Can't locate \S+)/
$level == 2 $msg =~ /^(Can't locate \S+)/
Truth table0%0/3
A and B
A= $level == 2B= $msg =~ /^(Can't locate \S+)/
ABresult
0X0
100
111
456 0 $msg = $1;
457 } elsif ($level > 2) {
458 0 die("Error: $msg");
459 }
460 0 ▶ if ($level == 1 || $level == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 1 or $level == 2) { } 0 0 0
Condition0%0/3
$level == 1 or $level == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$level == 1 or $level == 2
$level == 1 $level == 2
Truth table0%0/3
A or B
A= $level == 1B= $level == 2
ABresult
1X1
011
000
461 # On Windows, if the real ClearCase::CtCmd is missing hack
462 # in our own version that uses CAL directly.
463 0 if (MSWIN) {
464 eval { require Win32::OLE };
465 if ($@) {
466 warn("Warning: $msg\n") if $level == 2;
467 return undef;
468 } else {
469 warn("Warning: $msg, using CAL instead\n")
470 if $level == 2;
471 *ClearCase::CtCmd::new = \&_ctcmd_new;
472 *ClearCase::CtCmd::status = \&_ctcmd_status;
473 *ClearCase::CtCmd::exec = \&_ctcmd_cmd2cal;
474 *ClearCase::CtCmd::cleartool = \&_ctcmd_cmd2cal;
475 $ClearCase::CtCmd::VERSION = '1.01';
476 Win32::OLE->Option(Warn => 0);
477 }
478 } else {
479 0 my $rep = CYGWIN? "ipc" : "fork/exec";
480 0 ▶ warn("Warning: $msg, using $rep instead\n") if $level == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $level == 2 0 0 0
481 0 return undef;
482 }
483 } else {
484 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
485 0 $self->{CCAV_CTCMD} = 0;
486 0 return undef;
487 }
488 }
489 }
490 1 ▶ no strict 'refs'; # because $self may be a symbolic hash ref
Subroutine BEGIN: called CC=1 SCAR=0.0
491 0 ▶ if (defined($level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) { } 0 0 0
492 0 ▶ if ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) { } 0 0 0
493 0 ▶ ClearCase::CtCmd->VERSION(1.01) if $ClearCase::CtCmd::VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if $ClearCase::CtCmd::VERSION 0 0 0
494 0 $self->{CCAV_CTCMD} = 1;
495 # If setting a class attribute, export it to the
496 # env in case we fork a child using ClearCase::Argv.
497 ## NOT SURE WE REALLY WANT THIS IN THIS CASE ...??
498 ## $ENV{CLEARCASE_ARGV_CTCMD} = $self->{CCAV_CTCMD} if !ref($self);
499 0 return $self;
500 } else { # close up shop
501 0 ▶ delete $self->{CCAV_CTCMD} if exists $self->{CCAV_CTCMD};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"CCAV_CTCMD"} 0 0 0
502 delete $ENV{CLEARCASE_ARGV_CTCMD}
503 0 ▶ if $ENV{CLEARCASE_ARGV_CTCMD} && !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"CLEARCASE_ARGV_CTCMD"} and not ref $self 0 0 0
Condition0%0/3
$ENV{"CLEARCASE_ARGV_CTCMD"} and not ref $self
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"CLEARCASE_ARGV_CTCMD"} and not ref $self
$ENV{"CLEARCASE_ARGV_CTCMD"} not ref $self
Truth table0%0/3
A and not(B)
A= $ENV{"CLEARCASE_ARGV_CTCMD"}B= not ref $self
ABresult
0X0
100
111
504 0 return $self;
505 }
506 } else {
507 0 ▶ if (!defined($self->{CCAV_CTCMD}) && !defined($class->{CCAV_CTCMD})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"CCAV_CTCMD"} or defined $class->{"CCAV_CTCMD"}) 0 0 0
Condition0%0/3
defined $self->{"CCAV_CTCMD"} or defined $class->{"CCAV_CTCMD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $self->{"CCAV_CTCMD"} or defined $class->{"CCAV_CTCMD"}
defined $self->{"CCAV_CTCMD"} defined $class->{"CCAV_CTCMD"}
Truth table0%0/3
A or B
A= defined $self->{"CCAV_CTCMD"}B= defined $class->{"CCAV_CTCMD"}
ABresult
1X1
011
000
508 0 ▶ return $ENV{CLEARCASE_ARGV_CTCMD} ? $self : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CLEARCASE_ARGV_CTCMD'} ? : 0 0 0
509 }
510 0 ▶ return ($self->{CCAV_CTCMD} || $class->{CCAV_CTCMD}) ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'CCAV_CTCMD'} || $class->{'CCAV_CTCMD'} ? : 0 0 0
Condition0%0/3
$self->{"CCAV_CTCMD"} or $class->{"CCAV_CTCMD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"CCAV_CTCMD"} or $class->{"CCAV_CTCMD"}
$self->{"CCAV_CTCMD"} $class->{"CCAV_CTCMD"}
Truth table0%0/3
A or B
A= $self->{"CCAV_CTCMD"}B= $class->{"CCAV_CTCMD"}
ABresult
1X1
011
000
511 }
512 }
513  
514 0 ▶sub _ctcmd_new {
Subroutine _ctcmd_new: not called CC=1 SCAR=6.9
515 0 my $object = shift;
516 0 my $this = {};
517 0 %$this = @_;
518 0 bless $this, $object;
519 0 $this->{'status'} = 0;
520 0 return $this;
521 }
522  
523 0 ▶sub _ctcmd_status {
Subroutine _ctcmd_status: not called CC=1 SCAR=6.9
524 0 my $this = shift;
525 0 return $this->{'status'}
526 }
527  
528 0 ▶sub _ctcmd_cmd2cal {
Subroutine _ctcmd_cmd2cal: not called CC=18 SCAR=58.3
529 0 ▶ my $self = ref($_[0]) ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
530 # It may make more sense to stash a copy of this object rather than
531 # recreate it each time.
532 0 my $ccct = Win32::OLE->new('ClearCase.ClearTool');
533 # Turn list cmds into a quoted string.
534 0 ▶ my $cmd = (@_ == 1) ? $_[0] : join(' ', map {"'$_'"} @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
535 # Send the actual command to CAL and get stdout returned.
536 0 my $out = $ccct->CmdExec($cmd);
537 # Must reap the return code first, then get stderr IFF retcode != 0.
538 0 my $rc = int Win32::OLE->LastError;
539 0 ▶ my $err = $rc ? Win32::OLE->LastError . "\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$rc ? : 0 0 0
540 # Massage the output from CmdExec into cmdline-style format ...
541 # Turn the literal CRLF sequence into \n for subsequent chomp/splits.
542 0 for ($out, $err) {
543 0 ▶ s/\015?\012/\n/g if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 0 0
544 }
545 # Strip the OLE verbosity from any error messages.
546 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
547 0 $err =~ s%^OLE\s+exception.*%%;
548 0 $err =~ s%^\s*%%s;
549 0 $err =~ s%\s*Win32::OLE.*%\n%s;
550 }
551 0 ▶ $self->{'status'} = $rc if $self;
Branch: 1 branch
BranchTrueFalseTotal
if $self 0 0 0
552 0 my @results = $rc;
553 0 ▶ if (defined($out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) { } 0 0 0
554 0 ▶ if ($self && exists($self->{outfunc}) && ($self->{outfunc} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and exists $self->{'outfunc'} and $self->{'outfunc'} == 0) { } 0 0 0
Condition0%0/6
$self and exists $self->{"outfunc"} and $self->{"outfunc"} == 0
!ll&&!rl&&r
000
$self and exists $self->{"outfunc"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self and exists $self->{"outfunc"} and $self->{"outfunc"} == 0
$self exists $self->{"outfunc"} $self->{"outfunc"} == 0
Truth table0%0/4
A and B and C
A= $selfB= exists $self->{"outfunc"}C= $self->{"outfunc"} == 0
ABCresult
0XX0
10X0
1100
1111
555 0 print STDOUT $out;
556 } else {
557 0 push(@results, $out);
558 }
559 } else {
560 0 push(@results, q()); #Make sure $err will go into the 3rd slot
561 }
562 0 ▶ if ($self && exists($self->{errfunc}) && ($self->{errfunc} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and exists $self->{'errfunc'} and $self->{'errfunc'} == 0) { } 0 0 0
Condition0%0/6
$self and exists $self->{"errfunc"} and $self->{"errfunc"} == 0
!ll&&!rl&&r
000
$self and exists $self->{"errfunc"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self and exists $self->{"errfunc"} and $self->{"errfunc"} == 0
$self exists $self->{"errfunc"} $self->{"errfunc"} == 0
Truth table0%0/4
A and B and C
A= $selfB= exists $self->{"errfunc"}C= $self->{"errfunc"} == 0
ABCresult
0XX0
10X0
1100
1111
563 0 print STDERR $err;
564 } else {
565 0 push(@results, $err);
566 }
567 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
568 0 return @results;
569 } else {
570 0 ▶ $? = $rc if $rc;
Branch: 1 branch
BranchTrueFalseTotal
if $rc 0 0 0
571 0 ▶ print STDERR $results[2] if defined($results[2]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $results[2] 0 0 0
572 0 return $results[1];
573 }
574 }
575  
576 # Starts or stops a cleartool coprocess.
577 1 ▶sub ipc {
Subroutine ipc: called CC=24 SCAR=60.3
Pod undocumented
578 1 my $self = shift; # this might be an instance or a classname
579 1 ▶ no strict 'refs'; # because $self may be a symbolic hash ref
Subroutine BEGIN: called CC=1 SCAR=0.0
580 1 my $level = shift;
581 1 my $output = shift;
582 1 local $\ = ''; # no extra newlines e.g. under perl -le ...
583 1 ▶ if (defined($level) && !$level) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $level and not $level) { } 1 0 1
elsif (not defined $level) { } 0 0 0
Condition33%1/3
defined $level and not $level
!ll&&!rl&&r
001
MC/DC0%0/2
defined $level and not $level
defined $level not $level
Truth table33%1/3
A and not(B)
A= defined $levelB= not $level
ABresult
0X0
100
111
584 1 ▶ return 0 unless exists($self->{IPC});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"IPC"} 1 0 1
585 0 my $down = $self->{IPC}->{DOWN};
586 0 my $pid = $self->{IPC}->{PID};
587 0 delete $self->{IPC};
588 0 ▶ return 0 if --$pidcount{$pid};
Branch: 1 branch
BranchTrueFalseTotal
if --$pidcount{$pid} 0 0 0
589 # Send an explicit "exit" command and close up shop.
590 0 print $down "exit\n";
591 0 my $rc = close($down);
592 0 waitpid($pid, 0);
593 0 delete $pidcount{$pid};
594 0 ▶ return $rc || $?;
Condition0%0/3
$rc || $?
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc || $?
$rc $?
Truth table0%0/3
A || B
A= $rcB= $?
ABresult
1X1
011
000
595 } elsif (!defined($level)) {
596 0 ▶ return exists($self->{IPC}) ? $self : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'IPC'} ? : 0 0 0
597 }
598  
599 0 ▶ if ($self->ctcmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ctcmd) 0 0 0
600 0 $self->ctcmd(0); # shut down the CtCmd connection
601 }
602 0 ▶ if (exists($class->{IPC}) && $level =~ m%^\d+$%
Branch: 1 branch
BranchTrueFalseTotal
if (exists $class->{"IPC"} and $level =~ /^\d+$/ and not $self->{"CT"} and not $class->{"CT"} or $self->{"CT"} and $class->{"CT"} and $self->{"CT"} eq $class->{"CT"}) 0 0 0
Condition0%0/18
exists $class->{"IPC"} and $level =~ /^\d+$/ and not $self->{"CT"} and not $class->{"CT"} or $self->{"CT"} and $class->{"CT"} and $self->{"CT"} eq $class->{"CT"}
l!l&&r!l&&!r
000
exists $class->{"IPC"} and $level =~ /^\d+$/ and not $self->{"CT"} and not $class->{"CT"}
!ll&&!rl&&r
000
exists $class->{"IPC"} and $level =~ /^\d+$/ and not $self->{"CT"}
!ll&&!rl&&r
000
exists $class->{"IPC"} and $level =~ /^\d+$/
!ll&&!rl&&r
000
$self->{"CT"} and $class->{"CT"} and $self->{"CT"} eq $class->{"CT"}
!ll&&!rl&&r
000
$self->{"CT"} and $class->{"CT"}
!ll&&!rl&&r
000
MC/DC0%0/7
exists $class->{"IPC"} and $level =~ /^\d+$/ and not $self->{"CT"} and not $class->{"CT"} or $self->{"CT"} and $class->{"CT"} and $self->{"CT"} eq $class->{"CT"}
exists $class->{"IPC"} $level =~ /^\d+$/ not $self->{"CT"} not $class->{"CT"} $self->{"CT"} $class->{"CT"} $self->{"CT"} eq $class->{"CT"}
Truth table0%0/17
A and B and not(C) and not(D) or E and F and G
A= exists $class->{"IPC"}B= $level =~ /^\d+$/C= not $self->{"CT"}D= not $class->{"CT"}E= $self->{"CT"}F= $class->{"CT"}G= $self->{"CT"} eq $class->{"CT"}
ABCDEFGresult
1111XXX1
0XXX1111
10XX1111
110X1111
11101111
0XXX0XX0
0XXX10X0
0XXX1100
10XX0XX0
10XX10X0
10XX1100
110X0XX0
110X10X0
110X1100
11100XX0
111010X0
11101100
603 && !$self->{CT} && !$class->{CT}
604 || ($self->{CT} && $class->{CT} && $self->{CT} eq $class->{CT})) {
605 0 ▶ if (($self ne $class) && !$self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self ne $class and not $self->ipc) 0 0 0
Condition0%0/3
$self ne $class and not $self->ipc
!ll&&!rl&&r
000
MC/DC0%0/2
$self ne $class and not $self->ipc
$self ne $class not $self->ipc
Truth table0%0/3
A and not(B)
A= $self ne $classB= not $self->ipc
ABresult
0X0
100
111
606 0 ++$pidcount{$class->{IPC}->{PID}};
607 0 $self->{IPC}->{PID} = $class->{IPC}->{PID};
608 0 $self->{IPC}->{DOWN} = $class->{IPC}->{DOWN};
609 0 $self->{IPC}->{BACK} = $class->{IPC}->{BACK};
610 }
611 0 return $self;
612 }
613  
614 # This should never fail to load since it's built in.
615 0 require IPC::Open3;
616  
617 # Dies on failure.
618 0 my($down, $back);
619 0 ▶ my $view = ($level =~ /^\d+$/) ? '' : $level;
Branch: 1 branch
BranchTrueFalseTotal
$level =~ /^\d+$/ ? : 0 0 0
620 0 ▶ my @cmd = !$view ? ($self->ct, '-status')
Branch: 1 branch
BranchTrueFalseTotal
!$view ? : 0 0 0
621 : ($self->ct, qw(setview -exec), join(' ', $self->ct, '-status'), $view);
622 0 my $pid = IPC::Open3::open3($down, $back, undef, @cmd);
623  
624 # Set the "line discipline" to convert CRLF to \n.
625 0 binmode $back, ':crlf';
626  
627 0 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) 0 0 0
628 0 print $down "des -fmt '\\n' .\n";
629 0 ▶ while ($_ = <$back>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $back)) 0 0 0
630 0 ▶ last if /^Command 1 returned status/;
Branch: 1 branch
BranchTrueFalseTotal
if /^Command 1 returned status/ 0 0 0
631 0 ▶ push @{$output}, $_ unless /^$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^$/ 0 0 0
632 }
633 }
634  
635 0 $self->{IPC}->{DOWN} = $down;
636 0 $self->{IPC}->{BACK} = $back;
637 0 $self->{IPC}->{PID} = $pid;
638 0 ++$pidcount{$pid};
639  
640 0 return $self;
641 }
642  
643 0 ▶sub _cw_map {
Subroutine _cw_map: not called CC=8 SCAR=36.4
644 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
645 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
646 0 for (@_) {
647 0 ▶ next if s%^(vob:)?/cygdrive/([A-Za-z])%$1$2:%;
Branch: 1 branch
BranchTrueFalseTotal
if s[^(vob:)?/cygdrive/([A-Za-z])][$1$2:] 0 0 0
648 0 ▶ next if s%^(vob:)?/view%$1//view%;
Branch: 1 branch
BranchTrueFalseTotal
if s[^(vob:)?/view][$1//view] 0 0 0
649 0 ▶ if (m%^/[^/]%) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^/[^/]]) 0 0 0
650 0 my $p = dirname $_;
651 0 ▶ if ($p eq '/' && ! -r) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p eq '/' and not -r $_) { } 0 0 0
elsif (-r $p) { } 0 0 0
Condition0%0/3
$p eq "/" and not -r $_
!ll&&!rl&&r
000
MC/DC0%0/2
$p eq "/" and not -r $_
$p eq "/" not -r $_
Truth table0%0/3
A and not(B)
A= $p eq "/"B= not -r $_
ABresult
0X0
100
111
652 0 s%^/%\\%; # case of vob tags
653 } elsif (-r $p) {
654 0 $_ = Cygwin::posix_to_win_path($_);
655 }
656 }
657 }
658 }
659  
660 0 ▶sub _cvt_input_cw {
Subroutine _cvt_input_cw: not called CC=3 SCAR=24.8
661 0 my $self = shift;
662 0 ▶ return if $self->{WRAPPER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"WRAPPER"} 0 0 0
663 0 _cw_map @{$self->{AV_ARGS}};
664 0 for my $o (values %{$self->{AV_OPTS}}) {
665 0 _cw_map grep{$_}@{$o};
666 }
667 }
668  
669 # commands sent to ipc must be single line ones
670 0 ▶sub _ipc_nl_in_cmt {
Subroutine _ipc_nl_in_cmt: not called CC=8 SCAR=40.2
671 0 my $r = shift;
672 0 my ($i, $c, $v) = 0;
673 0 for (@{$r}) {
674 0 ▶ if (m%^-c(omment)?$%) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^-c(omment)?$/) { } 0 0 0
elsif (/^-(nc|c[fq])/) { } 0 0 0
elsif ($c and $i == $c + 1) { } 0 0 0
675 0 $c = $i;
676 } elsif (m%^-(nc|c[fq])%) {
677 0 last;
678 ▶ } elsif ($c and $i == $c + 1) {
Condition0%0/3
$c and $i == $c + 1
!ll&&!rl&&r
000
MC/DC0%0/2
$c and $i == $c + 1
$c $i == $c + 1
Truth table0%0/3
A and B
A= $cB= $i == $c + 1
ABresult
0X0
100
111
679 0 ▶ $v = $_ if m%\n%;
Branch: 1 branch
BranchTrueFalseTotal
if /\n/ 0 0 0
680 0 last;
681 }
682 0 $i++;
683 }
684 0 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
685 1 ▶ use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
686 0 my ($fh,$cfile) = tempfile;
687 0 print $fh $v;
688 0 close $fh;
689 0 splice @{$r} ,$c ,2 , ('-cfile', $cfile);
690 }
691 }
692  
693 0 ▶sub _ipc_cmd {
Subroutine _ipc_cmd: not called CC=34 SCAR=70.8
694 0 my $self = shift;
695 0 my ($disposition, $stdout, $stderr, @cmd) = @_;
696 0 local *_;
697 0 local $\ = ''; # no extra newlines e.g. under perl -le ...
698 0 _ipc_nl_in_cmt(\@cmd);
699 # Send the command to cleartool.
700 my $qm = ((MSWIN || CYGWIN) && !$self->{WRAPPER})?
701 0 ▶ sub { shift; s%\'%^'%g; return qq('$_'); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
702 0 ▶ : sub { quotemeta shift };
Subroutine __ANON__: not called CC=1 SCAR=6.9
703 my $cmd = join(' ', map {
704 0 ▶ m%^$|\s|[\[\]\(\)*"'?]% ?
Branch: 3 branches
BranchTrueFalseTotal
/^$|\s|[\[\]\(\)*"'?]/ ? : 0 0 0
/'/ ? : 0 0 0
/"/ ? : 0 0 0
705 (m%'% ?
706 (m%"% ?
707 $qm->($_) : qq("$_"))
708 : qq('$_'))
709 : $_
710 0 } grep {defined} @cmd);
711 # Handle verbosity.
712 0 my $dbg = $self->dbglevel;
713 0 ▶ $self->_dbg($dbg, '=>', \*STDERR, $cmd) if $dbg;
Branch: 1 branch
BranchTrueFalseTotal
if $dbg 0 0 0
714  
715 0 chomp $cmd;
716 0 my $down = $self->{IPC}->{DOWN};
717 0 print $down $cmd, "\n";
718  
719 # Supply custom comment on standard input if requested.
720 0 ▶ if (exists $self->{IPC}->{COMMENT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"IPC"}{"COMMENT"}) 0 0 0
721 0 my $input = $self->{IPC}->{COMMENT};
722 0 print $down $input, "\n.\n";
723 0 delete $self->{IPC}->{COMMENT};
724 }
725 0 my $man = ($self->{AV_PROG}->[1] eq 'man'); #Special case: errors ok
726 0 my $diff = ($self->{AV_PROG}->[1] eq 'diff');
727 0 my $manok; #Some man output already: no complete failure
728 # Read back the results and get command status.
729 0 my $rc = 0;
730 0 my $back = $self->{IPC}->{BACK};
731 0 ▶ while($_ = <$back>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $back)) 0 0 0
732 0 my ($last, $next, $err);
733 0 my $out = *STDOUT;
734 0 ▶ if (!$manok && m%^(?:clear|multi)tool.*?: (Error|Warning):%) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $manok and /^(?:clear|multi)tool.*?: (Error|Warning):/) { } 0 0 0
elsif (not $man and /^Comments for /) { } 0 0 0
elsif (s/^(.*)Command \d+ returned status (\d+)/$1/) { } 0 0 0
elsif (not $manok and $man) { } 0 0 0
Condition0%0/3
not $manok and /^(?:clear|multi)tool.*?: (Error|Warning):/
!ll&&!rl&&r
000
MC/DC0%0/2
not $manok and /^(?:clear|multi)tool.*?: (Error|Warning):/
not $manok /^(?:clear|multi)tool.*?: (Error|Warning):/
Truth table0%0/3
not(A) and B
A= not $manokB= /^(?:clear|multi)tool.*?: (Error|Warning):/
ABresult
0X0
100
111
735 0 ▶ if ($stderr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr) { } 0 0 0
736 0 $out = *STDERR;
737 0 $err = 1;
738 } else {
739 0 $next = 1;
740 }
741 ▶ } elsif (!$man && m%^Comments for %) {
Condition0%0/3
not $man and /^Comments for /
!ll&&!rl&&r
000
MC/DC0%0/2
not $man and /^Comments for /
not $man /^Comments for /
Truth table0%0/3
not(A) and B
A= not $manB= /^Comments for /
ABresult
0X0
100
111
742 0 ▶ if ($disposition) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disposition) { } 0 0 0
743 0 push(@$disposition, $_);
744 } else {
745 0 print $out $_;
746 }
747 0 ▶ while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 0 0 0
748 0 chomp;
749 0 s%\r$%% if MSWIN;
750 0 print $down "$_\n";
751 0 ▶ last if m%^\.$%;
Branch: 1 branch
BranchTrueFalseTotal
if /^\.$/ 0 0 0
752 }
753 } elsif (s%^(.*)Command \d+ returned status (\d+)%$1%) {
754 0 ▶ $rc = $2 unless $rc;
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 0 0 0
755 0 chomp;
756 0 ▶ $_ ? $last = 1 : last;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
757 ▶ } elsif (!$manok && $man) {
Condition0%0/3
not $manok and $man
!ll&&!rl&&r
000
MC/DC0%0/2
not $manok and $man
not $manok $man
Truth table0%0/3
not(A) and B
A= not $manokB= $man
ABresult
0X0
100
111
758 0 $manok = 1;
759 }
760 0 ▶ print '+ <=', $_ if $_ && $dbg >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $dbg >= 2 0 0 0
Condition0%0/3
$_ and $dbg >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$_ and $dbg >= 2
$_ $dbg >= 2
Truth table0%0/3
A and B
A= $_B= $dbg >= 2
ABresult
0X0
100
111
761 0 ▶ $rc = 1 if $diff && !m%^Files are identical%;
Branch: 1 branch
BranchTrueFalseTotal
if $diff and not /^Files are identical/ 0 0 0
Condition0%0/3
$diff and not /^Files are identical/
!ll&&!rl&&r
000
MC/DC0%0/2
$diff and not /^Files are identical/
$diff not /^Files are identical/
Truth table0%0/3
A and not(B)
A= $diffB= not /^Files are identical/
ABresult
0X0
100
111
762 0 ▶ next if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 0 0 0
763 0 $self->unixpath($_) if CYGWIN and !$self->{WRAPPER};
764 0 ▶ if ($stdout || ($err && $stderr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stdout or $err and $stderr) 0 0 0
Condition0%0/6
$stdout or $err and $stderr
l!l&&r!l&&!r
000
$err and $stderr
!ll&&!rl&&r
000
MC/DC0%0/3
$stdout or $err and $stderr
$stdout $err $stderr
Truth table0%0/4
A or B and C
A= $stdoutB= $errC= $stderr
ABCresult
1XX1
0111
00X0
0100
765 0 ▶ if ($disposition && (($err && $stderr == 1) || (!$err && $stdout == 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disposition and $err && $stderr == 1 || !$err && $stdout == 1) { } 0 0 0
Condition0%0/12
$disposition and $err && $stderr == 1 || !$err && $stdout == 1
!ll&&!rl&&r
000
$err and $stderr == 1 or not $err and $stdout == 1
l!l&&r!l&&!r
000
$err and $stderr == 1
!ll&&!rl&&r
000
not $err and $stdout == 1
!ll&&!rl&&r
000
MC/DC0%0/5
$disposition and $err && $stderr == 1 || !$err && $stdout == 1
$disposition $err $stderr == 1 not $err $stdout == 1
Truth table0%0/8
A and B and C or not(D) and E
A= $dispositionB= $errC= $stderr == 1D= not $errE= $stdout == 1
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
766 0 push(@$disposition, $_);
767 } else {
768 0 print $out $_;
769 }
770 }
771 0 ▶ last if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 0 0 0
772 }
773 0 return $rc;
774 }
775  
776 0 ▶sub fork_exec {
Subroutine fork_exec: not called CC=1 SCAR=6.9
Pod undocumented
777 0 my $self = shift;
778 0 $self->ipc(0);
779 0 $self->ctcmd(0);
780 }
781  
782 0 ▶sub exec_style {
Subroutine exec_style: not called CC=5 SCAR=29.9
Pod undocumented
783 0 my $self = shift;
784 0 my $style = shift;
785 0 ▶ if ($style) {
Branch: 1 branch
BranchTrueFalseTotal
if ($style) 0 0 0
786 1 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
787 0 ▶ $self->$style(shift || 3);
Condition0%0/2
shift() || 3
l!l
00
MC/DC0%0/1
shift() || 3
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
788 }
789 0 ▶ if ($self->ctcmd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ctcmd) { } 0 0 0
elsif ($self->ipc) { } 0 0 0
790 0 return "CTCMD";
791 } elsif ($self->ipc) {
792 0 return "IPC";
793 } else {
794 0 return "FORK";
795 }
796 }
797  
798 0 ▶sub _read_only {
Subroutine _read_only: not called CC=3 SCAR=24.8
799 0 my $self = shift;
800 0 ▶ if ($self->readonly =~ /^a/i) { # a=automatic
Branch: 1 branch
BranchTrueFalseTotal
if ($self->readonly =~ /^a/i) { } 0 0 0
801 0 my @cmd = $self->prog;
802 0 ▶ if ($cmd[-1] =~ m%^(ls|annotate|apropos|cat|des|diff|dospace|
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[-1] =~ /^(ls|annotate|apropos|cat|des|diff|dospace| file|getcache|getlog|help|host|man|pw| setview|space)/x) { } 0 0 0
803 file|getcache|getlog|help|host|man|pw|
804 setview|space)%x) {
805 0 return 1;
806 } else {
807 0 return 0;
808 }
809 } else {
810 0 return $self->SUPER::_read_only;
811 }
812 }
813  
814 # The cleartool command has quoting rules different from any system
815 # shell so we subclass the quoting method to deal with it. Not
816 # currently well tested with esoteric cmd lines such as mkattr.
817 ## THIS STUFF IS REALLY COMPLEX WITH ALL THE PERMUTATIONS
818 ## OF PLATFORMS, SUBCLASSES, SHELLS, AND APIs. WATCH OUT.
819 0 ▶sub quote {
Subroutine quote: not called CC=9 SCAR=45.0
Pod documented
820 0 my $self = shift;
821 # Don't quote the 2nd word where @_ = ('cleartool', 'pwv -s');
822 0 ▶ return @_ if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
823 0 ▶ return $self->SUPER::quote(@_) if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
824 # Ok, now we're looking at interactive-cleartool quoting ("man cleartool").
825 0 ▶ if (!MSWIN && $self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ipc) 0 0 0
826 # Special case - extract multiline comments from the cmd line and
827 # put them in the stdin stream when using UNIX co-process model.
828 0 ▶ for (my $i=0; $i < $#_; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#_) 0 0 0
829 0 ▶ if ($_[$i] eq '-c' && $_[$i+1] =~ m%\n%s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i] eq "-c" and $_[$i + 1] =~ /\n/s) 0 0 0
Condition0%0/3
$_[$i] eq "-c" and $_[$i + 1] =~ /\n/s
!ll&&!rl&&r
000
MC/DC0%0/2
$_[$i] eq "-c" and $_[$i + 1] =~ /\n/s
$_[$i] eq "-c" $_[$i + 1] =~ /\n/s
Truth table0%0/3
A and B
A= $_[$i] eq "-c"B= $_[$i + 1] =~ /\n/s
ABresult
0X0
100
111
830 0 $self->stdin("$_[$i+1]\n.");
831 0 splice(@_, $i, 2, '-cq');
832 0 last;
833 }
834 }
835 }
836 # Single quotes aren't understood by the &*&#$ Windows shell
837 # but cleartool gets them right so this quoting is simpler.
838 0 my $inpathnorm = $self->inpathnorm;
839 0 for (@_) {
840 0 $_ = Cygwin::posix_to_win_path($_) if CYGWIN && m%^/%;
841 # If requested, change / for \ in Windows file paths.
842 0 ▶ s%/%\\%g if $inpathnorm;
Branch: 1 branch
BranchTrueFalseTotal
if $inpathnorm 0 0 0
843 # Now quote embedded quotes ...
844 0 s%'%\\'%g;
845 # and then the entire string.
846 0 $_ = qq('$_');
847 }
848 0 return @_;
849 }
850  
851 # Hack - allow a comment to be registered here. The next command will
852 # see it with -c "comment" if in regular mode or with -cq and reading
853 # the comment from stdin if in ->ipc mode.
854 0 ▶sub comment {
Subroutine comment: not called CC=4 SCAR=30.0
Pod documented
855 0 my $self = shift;
856 0 my $cmnt = join("\n", @_);
857 0 my @prev = $self->opts;
858 0 ▶ if ($self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ipc) { } 0 0 0
859 0 ▶ $self->opts('-cq', @prev) if !grep /^-cq/, @prev;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^-cq/, @prev 0 0 0
860 0 $self->{IPC}->{COMMENT} = $cmnt;
861 } else {
862 0 ▶ $self->opts('-c', $cmnt, @prev) if !grep /^-c/, @prev;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^-c/, @prev 0 0 0
863 }
864 0 return $self;
865 }
866  
867 # Add -/ipc and -/ctcmd to list of supported attr-flags.
868 0 ▶sub attropts {
Subroutine attropts: not called CC=1 SCAR=6.9
Pod undocumented
869 0 my $self = shift;
870 0 return $self->SUPER::attropts(@_, qw(ipc ctcmd));
871 }
872  
873 0 ▶sub _chdir {
Subroutine _chdir: not called CC=3 SCAR=24.8
874 0 my $self = shift; # this might be an instance or a classname
875 0 my ($dir) = @_;
876 0 chomp $dir;
877 0 my $rc = CORE::chdir($dir);
878 0 ▶ if ($self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ipc) 0 0 0
879 0 ▶ my $ctcd = ref($self) ? $self->clone : __PACKAGE__->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
880 0 $ctcd->stdout(0)->argv('cd', $dir)->system;
881 }
882 0 return $rc;
883 }
884  
885 # Export our own functional interfaces as well.
886 0 ▶sub ctsystem { return __PACKAGE__->new(@_)->system }
Subroutine ctsystem: not called CC=1 SCAR=6.9
Pod undocumented
887 0 ▶sub ctexec { return __PACKAGE__->new(@_)->exec }
Subroutine ctexec: not called CC=1 SCAR=6.9
Pod undocumented
888 0 ▶sub ctqx { return __PACKAGE__->new(@_)->qx }
Subroutine ctqx: not called CC=1 SCAR=6.9
Pod undocumented
889 0 ▶sub ctpipe { return __PACKAGE__->new(@_)->pipe }
Subroutine ctpipe: not called CC=1 SCAR=6.9
Pod undocumented
890 0 ▶sub chdir { return __PACKAGE__->_chdir(@_) }
Subroutine chdir: not called CC=1 SCAR=6.9
Pod undocumented
891 1 *ctqv = \&ctqx; # just for consistency
892  
893 # Constructor, and copy constructor as clone, with $proto
894 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=30.3
Pod undocumented
895 0 my $proto = shift;
896 0 my $self = $proto->SUPER::new(@_);
897 0 ▶ if ($self->ipc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ipc) 0 0 0
898 1 ▶ no strict 'refs'; # $proto may be a symbolic hash
Subroutine BEGIN: called CC=1 SCAR=0.0
899 0 ▶ if ($proto->ipc && $self->{IPC}->{PID} == $proto->{IPC}->{PID}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto->ipc and $self->{"IPC"}{"PID"} == $proto->{"IPC"}{"PID"}) 0 0 0
Condition0%0/3
$proto->ipc and $self->{"IPC"}{"PID"} == $proto->{"IPC"}{"PID"}
!ll&&!rl&&r
000
MC/DC0%0/2
$proto->ipc and $self->{"IPC"}{"PID"} == $proto->{"IPC"}{"PID"}
$proto->ipc $self->{"IPC"}{"PID"} == $proto->{"IPC"}{"PID"}
Truth table0%0/3
A and B
A= $proto->ipcB= $self->{"IPC"}{"PID"} == $proto->{"IPC"}{"PID"}
ABresult
0X0
100
111
900 0 ++$pidcount{$self->{IPC}->{PID}};
901 # Correct the effect of the base cloning on globs
902 0 $self->{IPC}->{DOWN} = $proto->{IPC}->{DOWN};
903 0 $self->{IPC}->{BACK} = $proto->{IPC}->{BACK};
904 }
905 }
906 0 ▶ bless $self, ref($proto) ? ref($proto) : $proto;
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 0 0
907 0 return $self;
908 }
909 1 *clone = \&new;
910  
911 # Clean up leftover cleartool processes if user forgot to.
912 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
913 0 my $self = shift;
914 0 my $ret = $?;
915 0 ▶ $self->ipc(0) if $self->ipc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ipc 0 0 0
916 0 $? |= $ret;
917 }
918  
919 1 1;
920  
921 __END__
↑ Summary