Which.pm

filter: Statementstmt 97.7% 172 / 176 Branchbran 96.5% 83 / 86 Conditioncond 88.2% 15 / 17 MC/DCmcdc 81.8% 9 / 11 Subroutinesub 100% 25 / 25 Podpod 100% 15 / 15 totaltotal 96.6% 319 / 330 CC 55 SCAR 17.6
CC
55
Cov
97%
which
14.0
capabilities
8.1
get_systems
6.0
CRAP 5.8
« Which/Plugin/CVS.pm ↑ Summary
1 package VCS::Which;
2  
3 # Created on: 2009-05-16 16:54:35
4 # Create by: ivan
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 our $VERSION = version->new('0.6.9');
19  
20 2 our %systems;
21  
22 2 has [qw/dir systems/] => (
23 is => 'rw',
24 );
25 has [qw/_which _uptodate/] => (
26 is => 'rw',
27 36 ▶ default => sub {{}},
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 );
29  
30 18 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod documented
31 18 my ($self) = @_;
32  
33 18 ▶ if ( !%systems ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%VCS::Which::systems) 1 17 18
34 1 $self->get_systems();
35 }
36  
37 18 $self->load_systems();
38  
39 18 ▶ if ( $self->dir && -f $self->dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dir and -f $self->dir) 1 17 18
Condition100%3/3
$self->dir and -f $self->dir
!ll&&!rl&&r
6111
MC/DC100%2/2
$self->dir and -f $self->dir
$self->dir -f $self->dir
Truth table100%3/3
A and B
A= $self->dirB= -f $self->dir
ABresult
0X0
100
111
40 1 $self->dir( path($self->dir)->parent );
41 }
42  
43 18 return $self;
44 }
45  
46 18 ▶sub load_systems {
Subroutine load_systems: called CC=2 SCAR=6.9
Pod documented
47 18 my ( $self ) = @_;
48  
49 18 for my $module (keys %systems) {
50 90 $self->{systems}{$module} = $module->new;
51 }
52  
53 18 return;
54 }
55  
56 1 ▶sub get_systems {
Subroutine get_systems: called CC=6 SCAR=17.9
Pod documented
57 1 my ($self) = @_;
58  
59 1 for my $dir (@INC) {
60 8 ▶ if ( $dir !~ /^\/|^\w:\// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dir =~ m[^/|^\w:/]) 2 6 8
61 2 $dir = "./$dir";
62 }
63 2 ▶ my @files = glob "$dir/VCS/Which/Plugin/*.pm";
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 8 for my $file (@files) {
66 9 my $module = $file;
67 9 $module =~ s{\Q$dir\E/}{}xms;
68 9 $module =~ s{/}{::}gxms;
69 9 $module =~ s{[.]pm$}{}xms;
70  
71 9 ▶ next if $systems{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $VCS::Which::systems{$module} 4 5 9
72  
73 eval {
74 5 require $file;
75 5 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file } } or do { confess($@, "Error with $file / $module") } 5 0 5
76 0 confess $@, "Error with $file / $module";
77 };
78 5 $systems{$module} = 1;
79 }
80 }
81  
82 1 return;
83 }
84  
85 3 ▶sub capabilities {
Subroutine capabilities: called CC=8 SCAR=20.9
Pod documented
86 3 my ($self, $dir) = @_;
87 3 my $out;
88 my %out;
89  
90 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 2 1 3
91 2 $self->dir($dir);
92 }
93 else {
94 1 $dir = $self->dir;
95 }
96  
97 3 for my $system (values %{ $self->{systems} }) {
98  
99 15 $out .= $system->name . ' ' x (10 - length $system->name);
100 15 ▶ $out .= $system->installed ? ' installed ' : ' not installed';
Branch: 1 branch
BranchTrueFalseTotal
$system->installed ? : 6 9 15
101 15 $out{$system->name}{installed} = $system->installed;
102  
103 15 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 10 5 15
104 10 eval {
105 10 ▶ $out .= $system->used($dir) ? ' versioning' : ' not versioning';
Branch: 1 branch
BranchTrueFalseTotal
$system->used($dir) ? : 2 8 10
106 10 $out{$system->name}{installed} = $system->used($dir);
107 };
108 10 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VCS::Which::EVAL_ERROR) 0 10 10
109 0 warn "$system error in determining if the directory is used: $EVAL_ERROR\n";
110 0 $out .= ' NA';
111 0 $out{$system->name}{installed} = ' NA';
112 }
113 }
114  
115 15 $out .= "\n";
116 }
117  
118 3 ▶ return wantarray ? %out : $out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
119 }
120  
121 27 ▶sub which {
Subroutine which: called CC=14 SCAR=26.4
Pod documented
122 27 my ( $self, $dir ) = @_;
123  
124 27 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 5 22 27
125 5 $self->dir($dir);
126 }
127 else {
128 22 $dir = $self->dir;
129 }
130  
131 27 ▶ if ( $dir && -f $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir and -f $dir) 7 20 27
Condition100%3/3
$dir and -f $dir
!ll&&!rl&&r
1197
MC/DC100%2/2
$dir and -f $dir
$dir -f $dir
Truth table100%3/3
A and B
A= $dirB= -f $dir
ABresult
0X0
100
111
132 7 $dir = $self->dir( path($dir)->parent );
133 }
134  
135 27 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 26 27
136  
137 26 ▶ return $self->_which->{$dir} if exists $self->_which->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_which->{$dir} 9 17 26
138  
139 17 $self->_which->{$dir} = undef;
140 17 my %used;
141 my $min;
142  
143 17 for my $system (values %{ $self->{systems} }) {
144 85 ▶ my $used = eval { $system->used($dir) || 0 };
Condition100%2/2
$system->used($dir) || 0
l!l
1764
MC/DC100%1/1
$system->used($dir) || 0
$system->used($dir)
Truth table100%2/2
A
A= $system->used($dir)
Aresult
11
00
145 85 ▶ next if $EVAL_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if $VCS::Which::EVAL_ERROR 4 81 85
146  
147 81 ▶ if ( $used && ! defined $min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used and not defined $min) 17 64 81
Condition66%2/3
$used and not defined $min
!ll&&!rl&&r
64017
MC/DC50%1/2
$used and not defined $min
$used not defined $min
Truth table66%2/3
A and not(B)
A= $usedB= not defined $min
ABresult
0X0
100
111
148 17 $min = $used;
149 }
150  
151 # check that the directory is used and that it was found at a level closer to $dir that the last found system
152 81 ▶ if ( $used && $used <= $min ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used and $used <= $min) 17 64 81
Condition66%2/3
$used and $used <= $min
!ll&&!rl&&r
64017
MC/DC50%1/2
$used and $used <= $min
$used $used <= $min
Truth table66%2/3
A and B
A= $usedB= $used <= $min
ABresult
0X0
100
111
153 17 $self->_which->{$dir} = $system;
154 17 $min = $used;
155 }
156 }
157  
158 17 ▶ confess "Could not work out what plugin to use with '$dir'\n" if !$self->_which->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_which->{$dir} 0 17 17
159  
160 17 return $self->_which->{$dir};
161 }
162  
163 4 ▶sub uptodate {
Subroutine uptodate: called CC=4 SCAR=13.9
Pod documented
164 4 my ( $self, $dir ) = @_;
165  
166 4 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 2 2 4
167 2 $self->dir($dir);
168 }
169 else {
170 2 $dir = $self->dir;
171 }
172  
173 4 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 3 4
174  
175 3 ▶ return $self->_uptodate->{$dir} if exists $self->_uptodate->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_uptodate->{$dir} 1 2 3
176  
177 2 my $system = $self->which;
178  
179 2 return $self->_uptodate->{$dir} = $system->uptodate($dir);
180 }
181  
182 4 ▶sub exec {
Subroutine exec: called CC=4 SCAR=13.9
Pod documented
183 4 my ( $self, @args ) = @_;
184 4 my $dir;
185  
186 4 ▶ confess "Nothing to exec!" if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 3 4
187  
188 3 ▶ if (-e $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $args[0]) { } 1 2 3
189 1 $dir = $self->dir( shift @args );
190 }
191 else {
192 2 $dir = $self->dir;
193 }
194  
195 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
196  
197 2 my $system = $self->which;
198  
199 2 return $system->exec($dir, @args);
200 }
201  
202 5 ▶sub log {
Subroutine log: called CC=6 SCAR=17.9
Pod documented
203 5 my ( $self, $file, @args ) = @_;
204  
205 5 ▶ if ( $file && ! -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and not -e $file) 2 3 5
Condition100%3/3
$file and not -e $file
!ll&&!rl&&r
122
MC/DC100%2/2
$file and not -e $file
$file not -e $file
Truth table100%3/3
A and not(B)
A= $fileB= not -e $file
ABresult
0X0
100
111
206 2 unshift @args, $file;
207 2 undef $file;
208 }
209  
210 5 ▶ my $dir
Branch: 2 branches
BranchTrueFalseTotal
!defined($file) ? : 3 2 5
-f $file ? : 1 1 2
211 = !defined $file ? $self->dir
212 : -f $file ? path($file)->parent
213 : $file;
214  
215 5 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 4 5
216  
217 4 my $system = $self->which($dir);
218  
219 4 return $system->log($file, @args);
220 }
221  
222 5 ▶sub cat {
Subroutine cat: called CC=3 SCAR=11.0
Pod documented
223 5 my ( $self, $file, @args ) = @_;
224  
225 5 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 3 2 5
226 3 $self->dir($file);
227 }
228 else {
229 2 $file = $self->dir;
230 }
231  
232 5 ▶ confess "No file supplied!" if !$file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 4 5
233  
234 4 my $system = $self->which;
235  
236 4 return $system->cat($file, @args);
237 }
238  
239 3 ▶sub versions {
Subroutine versions: called CC=3 SCAR=11.0
Pod documented
240 3 my ( $self, $file, @args ) = @_;
241  
242 3 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 1 2 3
243 1 $self->dir($file);
244 }
245 else {
246 2 $file = $self->dir;
247 }
248  
249 3 ▶ confess "No file supplied!" if !$file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 2 3
250  
251 2 my $system = $self->which;
252  
253 2 return $system->versions($file, @args);
254 }
255  
256 3 ▶sub pull {
Subroutine pull: called CC=3 SCAR=11.0
Pod documented
257 3 my ( $self, $dir ) = @_;
258  
259 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 1 2 3
260 1 $self->dir($dir);
261 }
262 else {
263 2 $dir = $self->dir;
264 }
265  
266 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
267  
268 2 my $system = $self->which;
269  
270 2 return $system->pull($dir);
271 }
272  
273 3 ▶sub push {
Subroutine push: called CC=3 SCAR=11.0
Pod documented
274 3 my ( $self, $dir ) = @_;
275  
276 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 1 2 3
277 1 $self->dir($dir);
278 }
279 else {
280 2 $dir = $self->dir;
281 }
282  
283 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
284  
285 2 my $system = $self->which;
286  
287 2 return $system->push($dir);
288 }
289  
290 3 ▶sub status {
Subroutine status: called CC=3 SCAR=11.0
Pod documented
291 3 my ( $self, $dir ) = @_;
292  
293 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 1 2 3
294 1 $self->dir($dir);
295 }
296 else {
297 2 $dir = $self->dir;
298 }
299  
300 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
301  
302 2 my $system = $self->which;
303  
304 2 return $system->status($dir);
305 }
306  
307 3 ▶sub checkout {
Subroutine checkout: called CC=3 SCAR=11.0
Pod documented
308 3 my ( $self, $dir, @extra ) = @_;
309  
310 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 1 2 3
311 1 $self->dir($dir);
312 }
313 else {
314 2 $dir = $self->dir;
315 }
316  
317 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
318  
319 2 my $system = $self->which;
320  
321 2 return $system->checkout($dir, @extra);
322 }
323  
324 3 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod documented
325 3 my ( $self, $dir, @extra ) = @_;
326  
327 3 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 1 2 3
328 1 $self->dir($dir);
329 }
330 else {
331 2 $dir = $self->dir;
332 }
333  
334 3 ▶ confess "No directory supplied!" if !$dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 1 2 3
335  
336 2 my $system = $self->which;
337  
338 2 return $system->add($dir, @extra);
339 }
340  
341 2 1;
342  
343 __END__
« Which/Plugin/CVS.pm ↑ Summary