Toader/VCS.pm

filter: Statementstmt 10.8% 14 / 129 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 44.4% 4 / 9 Podpod 100% 5 / 5 totaltotal 11.0% 23 / 209 SCAR 64.0
CC
27
Cov
7%
new
132.0
add
72.0
delete
30.0
CRAP 604.2
« Toader/pathHelper.pm ↑ Summary Toader/Entry/Helper.pm »
1 package Toader::VCS;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Toader::VCS - Handles the VCS integration for Toader.
11  
12 =head1 VERSION
13  
14 Version 0.0.0
15  
16 =cut
17  
18 1 our $VERSION = '0.0.0';
19  
20 =head1 METHODS
21  
22 =head2 new
23  
24 This intiates the object.
25  
26 One argument is accepted and that is to Toader object
27 to use.
28  
29 my $tvcs=Toader::VCS->new($toader);
30 if ( $tvcs->error ){
31 warn('Error:'$tvcs->error.':'.$tvcs->errorFlag.': '.$tvcs->errorString);
32 }
33  
34 =cut
35  
36 sub new{
37 0 ▶ my $toader=$_[1];
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
38  
39 0 my $self={
40 error=>undef,
41 errorString=>'',
42 perror=>undef,
43 errorExtra=>{
44 flags=>{
45 1=>'noToader',
46 2=>'notToader',
47 3=>'getConfigFailed',
48 4=>'nothingToAdd',
49 5=>'doesNotExist',
50 6=>'notFileOrDir',
51 7=>'configNotUsable',
52 8=>'nonZeroExit',
53 9=>'getVCSfailed',
54 },
55 },
56 usable=>1,
57 };
58 0 bless $self;
59  
60 #make sure a Toader object is specified
61 0 ▶ if ( ! defined( $toader ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toader) 0 0 0
62 0 $self->{perror}=1;
63 0 $self->{error}=1;
64 0 $self->{errorString}='No toader object specified';
65 0 $self->warn;
66 0 return $self;
67 }
68  
69 #make sure it is a Toader object
70 0 ▶ if ( ref( $toader ) ne 'Toader' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $toader ne "Toader") 0 0 0
71 0 $self->{perror}=1;
72 0 $self->{error}=2;
73 0 $self->{errorString}='The passed object is "'.ref( $toader ).'" and not a Toader object';
74 0 $self->warn;
75 0 return $self;
76 }
77  
78 #saves the Toader object
79 0 $self->{toader}=$toader;
80  
81 #gets the config manually as Toader::Config depends on this module
82 0 my $configFile=$self->{toader}->getRootDir.'/.toader/config.ini';
83 0 ▶ if ( -f $configFile ){
Branch: 1 branch
BranchTrueFalseTotal
if (-f $configFile) { } 0 0 0
84 0 $self->{config}=Config::Tiny->read( $configFile );
85 0 ▶ if ( ! defined( $self->{config} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"config"}) 0 0 0
86 0 $self->{perror}=1;
87 0 $self->{error}=3;
88 0 $self->{errorString}='Config::Tiny failed to read "'.$configFile.'"';
89 0 $self->warn;
90 0 return $self;
91 }
92 }else{
93 0 $self->{config}=Config::Tiny->new;
94 }
95
96 #checks if it is usable or not
97 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"} and defined $self->{"config"}{"VCS"}{"addExec"} and defined $self->{"config"}{"VCS"}{"deleteExec"} and defined $self->{"config"}{"VCS"}{"underVCSexec"}) 0 0 0
Condition0%0/15
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"} and defined $self->{"config"}{"VCS"}{"addExec"} and defined $self->{"config"}{"VCS"}{"deleteExec"} and defined $self->{"config"}{"VCS"}{"underVCSexec"}
!ll&&!rl&&r
000
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"} and defined $self->{"config"}{"VCS"}{"addExec"} and defined $self->{"config"}{"VCS"}{"deleteExec"}
!ll&&!rl&&r
000
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"} and defined $self->{"config"}{"VCS"}{"addExec"}
!ll&&!rl&&r
000
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"}
!ll&&!rl&&r
000
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"}
!ll&&!rl&&r
000
MC/DC0%0/6
defined $self->{"config"}{"_"}{"vcs"} and $self->{"config"}{"_"}{"vcs"} and defined $self->{"config"}{"VCS"} and defined $self->{"config"}{"VCS"}{"addExec"} and defined $self->{"config"}{"VCS"}{"deleteExec"} and defined $self->{"config"}{"VCS"}{"underVCSexec"}
defined $self->{"config"}{"_"}{"vcs"} $self->{"config"}{"_"}{"vcs"} defined $self->{"config"}{"VCS"} defined $self->{"config"}{"VCS"}{"addExec"} defined $self->{"config"}{"VCS"}{"deleteExec"} defined $self->{"config"}{"VCS"}{"underVCSexec"}
Truth table0%0/7
A and B and C and D and E and F
A= defined $self->{"config"}{"_"}{"vcs"}B= $self->{"config"}{"_"}{"vcs"}C= defined $self->{"config"}{"VCS"}D= defined $self->{"config"}{"VCS"}{"addExec"}E= defined $self->{"config"}{"VCS"}{"deleteExec"}F= defined $self->{"config"}{"VCS"}{"underVCSexec"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
98 ( !defined( $self->{config}->{_}->{vcs} ) ) ||
99 ( !$self->{config}->{_}{vcs} ) ||
100 ( !defined( $self->{config}->{VCS} ) ) ||
101 ( !defined( $self->{config}->{VCS}->{addExec} ) ) ||
102 ( !defined( $self->{config}->{VCS}->{deleteExec} ) ) ||
103 ( !defined( $self->{config}->{VCS}->{underVCSexec} ) )
104 ){
105 0 $self->{usable}=0;
106 }
107  
108  
109 0 return $self;
110 }
111  
112 =head2 add
113  
114 This adds a file or directory.
115  
116 One option is accepted and that what is to be added.
117  
118 $tvcs->add($someFile);
119 if ( $tvcs->error ){
120 warn('Error:'$tvcs->error.':'.$tvcs->errorFlag.': '.$tvcs->errorString);
121 }
122  
123 =cut
124  
125 sub add{
126 0 ▶ my $self=$_[0];
Subroutine add: not called CC=8 SCAR=42.8
Pod documented
127 0 my $toAdd=$_[1];
128  
129 0 ▶ if ( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
130 0 return undef;
131 }
132  
133 0 ▶ if ( ! $self->{usable} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"usable"}) 0 0 0
134 0 $self->{error}=7;
135 0 $self->{errorString}='The VCS config is not usable';
136 0 $self->warn;
137 0 return undef;
138 }
139  
140 0 ▶ if ( ! defined( $toAdd ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toAdd) 0 0 0
141 0 $self->{error}=4;
142 0 $self->{errorString}='Nothing defined to add';
143 0 $self->warn;
144 0 return undef;
145 }
146  
147 0 ▶ if ( ! -e $toAdd ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $toAdd) 0 0 0
148 0 $self->{error}=5;
149 0 $self->{errorString}='What is to be added does not exist';
150 0 $self->warn;
151 0 return undef;
152 }
153  
154 0 ▶ if ( ( ! -f $toAdd ) || ( ! -d $toAdd ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $toAdd and -d $toAdd) 0 0 0
Condition0%0/3
-f $toAdd and -d $toAdd
!ll&&!rl&&r
000
MC/DC0%0/2
-f $toAdd and -d $toAdd
-f $toAdd -d $toAdd
Truth table0%0/3
A and B
A= -f $toAddB= -d $toAdd
ABresult
0X0
100
111
155 0 $self->{error}=6;
156 0 $self->{errorString}='What is to be added is not a file or directory';
157 0 $self->warn;
158 0 return undef;
159 }
160  
161 0 my $toExec=$self->{config}->{VCS}->{addExec};
162 0 $toExec=~s/\%\%\%item\%\%\%/$toAdd/g;
163 0 system($toExec);
164 0 my $exitCode=$?;
165 0 ▶ if ( $exitCode != 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($exitCode != 0) 0 0 0
166 0 $self->{error}=8;
167 0 $self->{errorString}='Exit integer returned "'.$exitCode.'". instead of "0"';
168 0 $self->warn;
169 0 return undef;
170 }
171
172 0 return 1;
173 }
174  
175 =head2 delete
176  
177 This deletes a file or directory.
178  
179 One option is accepted and that what is to be deleted.
180  
181 $tvcs->delete($someFile);
182 if ( $tvcs->error ){
183 warn('Error:'$tvcs->error.':'.$tvcs->errorFlag.': '.$tvcs->errorString);
184 }
185  
186 =cut
187  
188 sub delete{
189 0 ▶ my $self=$_[0];
Subroutine delete: not called CC=5 SCAR=34.0
Pod documented
190 0 my $toDelete=$_[1];
191  
192 0 ▶ if ( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
193 0 return undef;
194 }
195  
196 0 ▶ if ( ! $self->{usable} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"usable"}) 0 0 0
197 0 $self->{error}=7;
198 0 $self->{errorString}='The VCS config is not usable';
199 0 $self->warn;
200 0 return undef;
201 }
202  
203 0 ▶ if ( ! defined( $toDelete ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toDelete) 0 0 0
204 0 $self->{error}=4;
205 0 $self->{errorString}='Nothing defined to delete';
206 0 $self->warn;
207 0 return undef;
208 }
209  
210 0 my $toExec=$self->{config}->{VCS}->{deleteExec};
211 0 $toExec=~s/\%\%\%item\%\%\%/$toDelete/g;
212 0 system($toExec);
213 0 my $exitCode=$?;
214 0 ▶ if ( $exitCode != 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($exitCode != 0) 0 0 0
215 0 $self->{error}=8;
216 0 $self->{errorString}='Exit integer returned "'.$exitCode.'". instead of "0"';
217 0 $self->warn;
218 0 return undef;
219 }
220
221 0 return 1;
222 }
223  
224 =head2 underVCS
225  
226 This checks if something is under VCS.
227  
228 The returned value is a Perl boolean.
229  
230 my $underVCS=$tvcs->underVCS($someFile);
231 if ( $tvcs->error ){
232 warn('Error:'$tvcs->error.':'.$tvcs->errorFlag.': '.$tvcs->errorString);
233 }
234  
235 =cut
236  
237 sub underVCS{
238 0 ▶ my $self=$_[0];
Subroutine underVCS: not called CC=5 SCAR=34.0
Pod documented
239 0 my $toCheck=$_[1];
240  
241 0 ▶ if ( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
242 0 return undef;
243 }
244  
245 0 ▶ if ( ! $self->{usable} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"usable"}) 0 0 0
246 0 $self->{error}=7;
247 0 $self->{errorString}='The VCS config is not usable';
248 0 $self->warn;
249 0 return undef;
250 }
251  
252 0 ▶ if ( ! defined( $toCheck ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toCheck) 0 0 0
253 0 $self->{error}=4;
254 0 $self->{errorString}='Nothing defined to check';
255 0 $self->warn;
256 0 return undef;
257 }
258  
259 0 my $toExec=$self->{config}->{VCS}->{underVCSexec};
260 0 $toExec=~s/\%\%\%item\%\%\%/$toCheck/g;
261 0 system($toExec);
262 0 my $exitCode=$?;
263 0 ▶ if ( $exitCode != 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($exitCode != 0) 0 0 0
264 0 $self->{error}=8;
265 0 $self->{errorString}='Exit integer returned "'.$exitCode.'". instead of "0"';
266 0 $self->warn;
267 0 return undef;
268 }
269
270 0 return 1;
271 }
272  
273 =head2 usable
274  
275 Checks if this object is usable or not.
276  
277 $tvcs->usable;
278  
279 =cut
280  
281 sub usable{
282 0 ▶ my $self=$_[0];
Subroutine usable: not called CC=2 SCAR=17.9
Pod documented
283  
284 0 ▶ if ( $self->perror ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->perror) 0 0 0
285 0 return undef;
286 }
287
288 0 return $self->{usable};
289 }
290  
291 =head1 ERROR CODES/FLAGS/HANDLING
292  
293 Error handling is provided by L<Error::Helper>.
294  
295 =head2 1, noToader
296  
297 No L<Toader> object specified.
298  
299 =haed2 2, notToader
300  
301 The object specified is not a L<Toader> object.
302  
303 =head2 3, getConfigFailed
304  
305 Failed to read the .toader/config.ini .
306  
307 =head2 4, nothingToAdd
308  
309 Nothing specified to add.
310  
311 =head2 5, doesNotExist
312  
313 What is to be added does not exist
314  
315 =head2 6, notFileOrDir
316  
317 The specified item is not a file or directory.
318  
319 =head2 7, configNotUsable
320  
321 The configuration is not usable.
322  
323 This most likely means either a config value is missing or it is disabled, such as in the example below.
324  
325 vcs=0
326 [VCS]
327 addExec=svn add --parents %%%item%%% > /dev/null
328 deleteExec=svn del %%%item%%% > /dev/null
329 underVCSexec=svn info %%%info%%% > /dev/null
330  
331  
332 =head2 8, nonZeroExit
333  
334 One of the commands to execute returned a non-zero status.
335  
336 =head2 9, getVCSfailed
337  
338 Toader->getVCS errored.
339  
340 =head1 AUTHOR
341  
342 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
343  
344 =head1 BUGS
345  
346 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
347 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll
348 automatically be notified of progress on your bug as I make changes.
349  
350  
351  
352  
353 =head1 SUPPORT
354  
355 You can find documentation for this module with the perldoc command.
356  
357 perldoc Toader::VCS
358  
359  
360 You can also look for information at:
361  
362 =over 4
363  
364 =item * RT: CPAN's request tracker
365  
366 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
367  
368 =item * AnnoCPAN: Annotated CPAN documentation
369  
370 L<http://annocpan.org/dist/Toader>
371  
372 =item * CPAN Ratings
373  
374 L<http://cpanratings.perl.org/d/Toader>
375  
376 =item * Search CPAN
377  
378 L<http://search.cpan.org/dist/Toader/>
379  
380 =back
381  
382  
383 =head1 ACKNOWLEDGEMENTS
384  
385  
386 =head1 LICENSE AND COPYRIGHT
387  
388 Copyright 2013 Zane C. Bowers-Hadley.
389  
390 This program is free software; you can redistribute it and/or modify it
391 under the terms of either: the GNU General Public License as published
392 by the Free Software Foundation; or the Artistic License.
393  
394 See http://dev.perl.org/licenses/ for more information.
395  
396  
397 =cut
398  
399 1 1; # End of Toader::VCS
« Toader/pathHelper.pm ↑ Summary Toader/Entry/Helper.pm »