blib/lib/VCS/StarTeam.pm

filter: Statementstmt 42.4% 53 / 125 Branchbran 24.3% 18 / 74 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 36.3% 8 / 22 Podpod 92.3% 12 / 13 totaltotal 37.7% 92 / 244 CC 41 SCAR 30.2
CC
41
Cov
35%
_co
42.0
_ci
42.0
_diff
42.0
CRAP 20.4
↑ Summary
1 package VCS::StarTeam;
2
3 #require 5.005_62;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 require Exporter;
10
11 1 our @ISA = qw(Exporter);
12
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16
17 # This allows declaration use VCS::StarTeam ':all';
18 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19 # will save memory.
20 1 our %EXPORT_TAGS = ( 'all' => [ qw(
21
22 ) ] );
23
24 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25
26 1 our @EXPORT = qw(
27 hist history list log checkout get co diff vdiff checkin ci put
28 );
29
30 1 our $VERSION = '0.08';
31
32
33 # Preloaded methods go here.
34
35 #
36 # constructor
37 #
38 1 ▶sub new {
Subroutine new: called CC=10 SCAR=26.5
Pod undocumented
39 1 my( $class, $optionRef ) = @_;
40
41 1 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
42
43 1 ▶ my( $self ) = ( ref( $optionRef ) eq 'HASH' ) ? $optionRef : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $optionRef eq 'HASH' ? : 1 0 1
44
45 my( $username ) = $^O eq 'MSWin32' ? $ENV{'USERNAME'}
46 : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
47 : $^O eq 'MacOS' ? $ENV{'USER'}
48 1 ▶ : eval { getpwuid($<) }; # May be missing
Branch: 3 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 1 1
$^O eq 'os2' ? : 0 1 1
$^O eq 'MacOS' ? : 0 1 1
Condition0%0/3
$ENV{"USER"} or $ENV{"LOGNAME"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"USER"} or $ENV{"LOGNAME"}
$ENV{"USER"} $ENV{"LOGNAME"}
Truth table0%0/3
A or B
A= $ENV{"USER"}B= $ENV{"LOGNAME"}
ABresult
1X1
011
000
49
50 1 my( %default ) = (
51 'batchmode' => 0,
52 'compress' => 0,
53 'host' => 'localhost',
54 'endpoint' => '1024',
55 'project' => '',
56 'password' => '',
57 'path' => '',
58 'recurse' => 0,
59 'stoponerror' => 0,
60 'username' => $username,
61 'verbose' => 0,
62 'view' => '',
63 );
64
65 1 for my $option ( keys( %default ) ) {
66 12 ▶ $self -> {$option} = $default{$option} if ( ! defined( $self -> {$option} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$option} 6 6 12
67 12 print "$option = $self->{$option}\n";
68 }
69
70 1 ▶ croak("Failure: No project name specified") if ( ! $self->{'project'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"project"} 0 1 1
71
72 1 return bless $self, $class;
73 }
74
75 #
76 # private routine for creating project string for stcmd commands
77 #
78 1 ▶sub _getpparam {
Subroutine _getpparam: called CC=1 SCAR=0.0
79 1 my( $self ) = shift;
80 my( $pparam ) = join( '', $self->{'username'}, ":",
81 $self->{'password'}, "\@", $self->{'host'}, ":",
82 $self->{'endpoint'}, "/", $self->{'project'}, "/",
83 1 $self->{'view'}, "/", $self->{'path'} );
84 1 return $pparam;
85 }
86
87 #
88 # hist methods
89 #
90 0 ▶sub history {
Subroutine history: not called CC=1 SCAR=6.9
Pod documented
91 # convenience method for calling _hist
92 0 my( $self ) = shift;
93 0 $self->_hist( @_ );
94 }
95
96 1 ▶sub hist {
Subroutine hist: called CC=1 SCAR=0.0
Pod documented
97 # convenience method for calling _hist
98 1 my( $self ) = shift;
99 1 $self->_hist( @_ );
100 }
101
102 0 ▶sub log {
Subroutine log: not called CC=1 SCAR=6.9
Pod documented
103 # convenience method for calling _hist
104 0 my( $self ) = shift;
105 0 $self->_hist( @_ );
106 }
107
108 1 ▶sub _hist {
Subroutine _hist: called CC=5 SCAR=16.6
109 # run 'stcmd hist...'
110 1 my( $self ) = shift;
111 1 my( @args ) = ( 'stcmd' );
112 1 push( @args, 'hist' );
113 1 push( @args, '-nologo' );
114 1 push( @args, join( '', '-p ', "\"", $self->_getpparam( ), "\"" ) );
115 1 ▶ push( @args, '-cmp' ) unless $self->{'compress'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compress"} == 0 0 1 1
116 1 ▶ push( @args, '-is' ) unless $self->{'recurse'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"recurse"} == 0 0 1 1
117 1 ▶ push( @args, '-x' ) unless $self->{'batchmode'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"batchmode"} == 0 0 1 1
118 1 ▶ push( @args, '-stop' ) unless $self->{'stoponerror'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stoponerror"} == 0 0 1 1
119 1 push( @args, @_ );
120 1 $self->_runOrCroak( @args );
121 }
122
123 #
124 # list methods
125 #
126 0 ▶sub list {
Subroutine list: not called CC=4 SCAR=30.0
Pod documented
127 # run 'stcmd list...'
128 0 my( $self ) = shift;
129 0 my( @args ) = ( 'stcmd' );
130 0 push( @args, 'list' );
131 0 push( @args, '-nologo' );
132 0 push( @args, join( '', '-p ', "\"", $self->_getpparam( ), "\"" ) );
133 0 ▶ push( @args, '-cmp' ) unless $self->{'compress'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compress"} == 0 0 0 0
134 0 ▶ push( @args, '-x' ) unless $self->{'batchmode'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"batchmode"} == 0 0 0 0
135 0 ▶ push( @args, '-stop' ) unless $self->{'stoponerror'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stoponerror"} == 0 0 0 0
136 0 push( @args, @_ );
137 0 $self->_runOrCroak( @args );
138 }
139
140 #
141 # checkout methods
142 #
143 0 ▶sub checkout {
Subroutine checkout: not called CC=1 SCAR=6.9
Pod documented
144 # convenience method for calling _co
145 0 my( $self ) = shift;
146 0 $self->_co( @_ );
147 }
148
149 0 ▶sub co {
Subroutine co: not called CC=1 SCAR=6.9
Pod documented
150 # convenience method for calling _co
151 0 my( $self ) = shift;
152 0 $self->_co( @_ );
153 }
154
155 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
156 # convenience method for calling _co
157 0 my( $self ) = shift;
158 0 $self->_co( @_ );
159 }
160
161 0 ▶sub _co {
Subroutine _co: not called CC=6 SCAR=37.4
162 # run 'stcmd co...'
163 0 my( $self ) = shift;
164 0 my( @args ) = ( 'stcmd' );
165 0 push( @args, 'co' );
166 0 push( @args, '-nologo' );
167 0 push( @args, join( '', '-p ', "\"", $self->_getpparam( ), "\"" ) );
168 0 ▶ push( @args, '-q' ) unless $self->{'verbose'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"verbose"} == 0 0 0 0
169 0 ▶ push( @args, '-cmp' ) unless $self->{'compress'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compress"} == 0 0 0 0
170 0 ▶ push( @args, '-is' ) unless $self->{'recurse'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"recurse"} == 0 0 0 0
171 0 ▶ push( @args, '-x' ) unless $self->{'batchmode'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"batchmode"} == 0 0 0 0
172 0 ▶ push( @args, '-stop' ) unless $self->{'stoponerror'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stoponerror"} == 0 0 0 0
173 0 push( @args, @_ );
174 0 $self->_runOrCroak( @args );
175 }
176
177 #
178 # checkin methods
179 #
180 0 ▶sub checkin {
Subroutine checkin: not called CC=1 SCAR=6.9
Pod documented
181 # convenience method for calling _ci
182 0 my( $self ) = shift;
183 0 $self->_ci( @_ );
184 }
185
186 0 ▶sub ci {
Subroutine ci: not called CC=1 SCAR=6.9
Pod documented
187 # convenience method for calling _ci
188 0 my( $self ) = shift;
189 0 $self->_ci( @_ );
190 }
191
192 0 ▶sub put {
Subroutine put: not called CC=1 SCAR=6.9
Pod documented
193 # convenience method for calling _ci
194 0 my( $self ) = shift;
195 0 $self->_ci( @_ );
196 }
197
198 0 ▶sub _ci {
Subroutine _ci: not called CC=6 SCAR=37.4
199 # run 'stcmd ci...'
200 0 my( $self ) = shift;
201 0 my( @args ) = ( 'stcmd' );
202 0 push( @args, 'ci' );
203 0 push( @args, '-nologo' );
204 0 push( @args, join( '', '-p ', "\"", $self->_getpparam( ), "\"" ) );
205 0 ▶ push( @args, '-q' ) unless $self->{'verbose'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"verbose"} == 0 0 0 0
206 0 ▶ push( @args, '-cmp' ) unless $self->{'compress'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compress"} == 0 0 0 0
207 0 ▶ push( @args, '-is' ) unless $self->{'recurse'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"recurse"} == 0 0 0 0
208 0 ▶ push( @args, '-x' ) unless $self->{'batchmode'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"batchmode"} == 0 0 0 0
209 0 ▶ push( @args, '-stop' ) unless $self->{'stoponerror'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stoponerror"} == 0 0 0 0
210 0 push( @args, @_ );
211 0 $self->_runOrCroak( @args );
212 }
213
214 #
215 # diff methods
216 #
217 0 ▶sub diff {
Subroutine diff: not called CC=1 SCAR=6.9
Pod documented
218 # convenience method for calling _diff
219 0 my( $self ) = shift;
220 0 $self->_diff( @_ );
221 }
222
223 0 ▶sub vdiff {
Subroutine vdiff: not called CC=1 SCAR=6.9
Pod documented
224 # convenience method for calling _diff
225 0 my( $self ) = shift;
226 0 $self->_diff( @_ );
227 }
228
229 0 ▶sub _diff {
Subroutine _diff: not called CC=6 SCAR=37.4
230 # run 'stcmd diff...'
231 0 my( $self ) = shift;
232 0 my( @args ) = ( 'stcmd' );
233 0 push( @args, 'diff' );
234 0 push( @args, '-nologo' );
235 0 push( @args, join( '', '-p ', "\"", $self->_getpparam( ), "\"" ) );
236 0 ▶ push( @args, '-q' ) unless $self->{'verbose'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"verbose"} == 0 0 0 0
237 0 ▶ push( @args, '-cmp' ) unless $self->{'compress'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compress"} == 0 0 0 0
238 0 ▶ push( @args, '-is' ) unless $self->{'recurse'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"recurse"} == 0 0 0 0
239 0 ▶ push( @args, '-x' ) unless $self->{'batchmode'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"batchmode"} == 0 0 0 0
240 0 ▶ push( @args, '-stop' ) unless $self->{'stoponerror'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stoponerror"} == 0 0 0 0
241 0 push( @args, @_ );
242 0 $self->_runOrCroak( @args );
243 }
244
245 # --------------------------------------------------------------------------
246 # The standard way to run a system command and report on the result.
247 #
248 # I "borrowed" and modified this routine from Ron Savage's VCS::CVS module.
249 #
250 1 ▶sub _runOrCroak {
Subroutine _runOrCroak: called CC=10 SCAR=31.6
251 1 my( $self, @args ) = @_;
252
253 1 my( $verbose ) = $self->{'verbose'};
254
255 1 my( $result ) = 0xffff & system( @args );
256
257 1 ▶ print "Command: @args\n" unless $verbose == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose == 0 1 0 1
258
259 1 ▶ if ( $result == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($result == 0) { } 0 1 1
elsif ($result == 65280) { } 0 1 1
elsif ($result > 128) { } 1 0 1
260 0 ▶ print 'Success. ' unless $verbose == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose == 0 0 0 0
261 } elsif ( $result == 0xff00 ) {
262 0 warn "Failure: $!. ";
263 } elsif ( $result > 0x80 ) {
264 1 $result >>= 8;
265 1 ▶ print "Exit status: $result. " unless $verbose == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose == 0 1 0 1
266 } else {
267 0 ▶ if ( $result & 0x80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result & 128) 0 0 0
268 0 $result &= ~0x80;
269 0 print 'Coredump from ';
270 }
271
272 0 print "Signal $result. ";
273 }
274
275 1 ▶ printf( "Result: %#04x\n", $result ) unless $verbose == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose == 0 1 0 1
276 1 ▶ croak( "Failure: Can't run '@args'" ) if ( $result );
Branch: 1 branch
BranchTrueFalseTotal
if $result 1 0 1
277
278 } # End of runOrCroak.
279
280 1 1;
281 __END__
↑ Summary