lib/App/Virtualenv.pm

filter: Statementstmt 20.8% 41 / 197 Branchbran 0.0% 0 / 84 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 58 Subroutinesub 54.1% 13 / 24 Podpod 100% 11 / 11 totaltotal 13.5% 65 / 479 CC 82 SCAR 52.2
CC
82
Cov
11%
find_virtualenv_path
306.0
main
306.0
deactivate
272.0
CRAP 184.8
↑ Summary lib/App/Virtualenv/Module.pm »
1 package App::Virtualenv;
2 =head1 NAME
3  
4 App::Virtualenv - Perl virtual environment
5  
6 =head1 VERSION
7  
8 version 2.07
9  
10 =head1 SYNOPSIS
11  
12 #!/bin/sh
13 perl -MApp::Virtualenv -erun -- environment_path
14  
15 =head1 DESCRIPTION
16  
17 App::Virtualenv is a Perl package to create isolated Perl virtual environments, like Python virtual environment.
18  
19 See also: L<virtualenv.pl|https://metacpan.org/pod/distribution/App-Virtualenv/lib/App/Virtualenv/virtualenv.pl>
20  
21 =cut
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use feature qw(switch);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶no if ($] >= 5.018), 'warnings' => 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Lazy::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35  
36 BEGIN
37 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 require Exporter;
39 1 our $VERSION = '2.07';
40 1 our @ISA = qw(Exporter);
41 1 our @EXPORT = qw(main run);
42 1 our @EXPORT_OK = qw();
43 }
44  
45  
46 =head1 Functions
47  
48 =head2 sh(@args)
49  
50 runs shell program defined in SHELL environment variable, otherwise /bin/sh
51  
52 @args: I<arguments of shell program>
53  
54 return value: I<exit code of shell program>
55  
56 =cut
57 sub sh
58 0 ▶{
Subroutine sh: not called CC=2 SCAR=17.9
Pod documented
59 0 my (@args) = @_;
60 0 ▶ return system2((defined $ENV{SHELL})? $ENV{SHELL}: "/bin/sh", @args);
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'SHELL'} ? : 0 0 0
61 }
62  
63 =head2 perl(@args)
64  
65 runs Perl interpreter
66  
67 @args: I<arguments of Perl interpreter>
68  
69 return value: I<exit code of Perl interpreter>
70  
71 =cut
72 sub perl
73 0 ▶{
Subroutine perl: not called CC=1 SCAR=6.9
Pod documented
74 0 my (@args) = @_;
75 0 return system2($Config{perlpath}, @args);
76 }
77  
78 =head2 activate($virtualenv_path)
79  
80 activates Perl virtual environment
81  
82 $virtualenv_path: I<virtual environment path>
83  
84 return value: I<virtual environment path if success, otherwise undef>
85  
86 =cut
87 sub activate
88 0 ▶{
Subroutine activate: not called CC=7 SCAR=40.3
Pod documented
89 0 my ($virtualenv_path) = @_;
90 0 ▶ return unless defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5" 0 0 0
Condition0%0/6
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5"
Truth table0%0/4
A and B and C
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"
ABCresult
0XX0
10X0
1100
1111
91 0 $virtualenv_path = Cwd::realpath($virtualenv_path);
92  
93 0 deactivate(1);
94  
95 0 $ENV{_OLD_PERL_VIRTUAL_ENV} = $ENV{PERL_VIRTUAL_ENV};
96 0 $ENV{PERL_VIRTUAL_ENV} = $virtualenv_path;
97  
98 0 $ENV{_OLD_PERL_VIRTUAL_PATH} = $ENV{PATH};
99 0 ▶ $ENV{PATH} = "$virtualenv_path/bin".((defined $ENV{PATH})? ":${ENV{PATH}}": "");
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PATH'} ? : 0 0 0
100  
101 0 $ENV{_OLD_PERL_VIRTUAL_PERL5LIB} = $ENV{PERL5LIB};
102 0 ▶ $ENV{PERL5LIB} = "$virtualenv_path/lib/perl5".((defined $ENV{PERL5LIB})? ":${ENV{PERL5LIB}}": "");
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL5LIB'} ? : 0 0 0
103  
104 0 $ENV{_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT} = $ENV{PERL_LOCAL_LIB_ROOT};
105 0 $ENV{PERL_LOCAL_LIB_ROOT} = "$virtualenv_path";
106  
107 0 $ENV{_OLD_PERL_VIRTUAL_PERL_MB_OPT} = $ENV{PERL_MB_OPT};
108 0 $ENV{PERL_MB_OPT} = "--install_base \"$virtualenv_path\"";
109  
110 0 $ENV{_OLD_PERL_VIRTUAL_PERL_MM_OPT} = $ENV{PERL_MM_OPT};
111 0 $ENV{PERL_MM_OPT} = "INSTALL_BASE=$virtualenv_path";
112  
113 0 $ENV{_OLD_PERL_VIRTUAL_PS1} = $ENV{PS1};
114 0 ▶ $ENV{PS1} = "(".basename($virtualenv_path).") ".((defined $ENV{PS1})? $ENV{PS1}: "");
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PS1'} ? : 0 0 0
115  
116 0 return $virtualenv_path;
117 }
118  
119 =head2 deactivate($nondestructive)
120  
121 deactivates Perl virtual environment
122  
123 $nondestructive: I<leaves envionment variables as it is, unless there are old envionment variables>
124  
125 return value: I<always 1>
126  
127 =cut
128 sub deactivate
129 0 ▶{
Subroutine deactivate: not called CC=16 SCAR=56.1
Pod documented
130 0 my ($nondestructive) = @_;
131  
132 0 ▶ $nondestructive = not defined($ENV{PERL_VIRTUAL_ENV}) if not defined($nondestructive);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nondestructive 0 0 0
133  
134 0 ▶ $ENV{PERL_VIRTUAL_ENV} = $ENV{_OLD_PERL_VIRTUAL_ENV} if defined($ENV{_OLD_PERL_VIRTUAL_ENV}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_ENV"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_ENV"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_ENV"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_ENV"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_ENV"}B= not $nondestructive
ABresult
1X1
011
000
135 0 undef $ENV{_OLD_PERL_VIRTUAL_ENV};
136  
137 0 ▶ $ENV{PATH} = $ENV{_OLD_PERL_VIRTUAL_PATH} if defined($ENV{_OLD_PERL_VIRTUAL_PATH}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PATH"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PATH"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PATH"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PATH"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PATH"}B= not $nondestructive
ABresult
1X1
011
000
138 0 undef $ENV{_OLD_PERL_VIRTUAL_PATH};
139  
140 0 ▶ $ENV{PERL5LIB} = $ENV{_OLD_PERL_VIRTUAL_PERL5LIB} if defined($ENV{_OLD_PERL_VIRTUAL_PERL5LIB}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PERL5LIB"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PERL5LIB"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PERL5LIB"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PERL5LIB"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PERL5LIB"}B= not $nondestructive
ABresult
1X1
011
000
141 0 undef $ENV{_OLD_PERL_VIRTUAL_PERL5LIB};
142  
143 0 ▶ $ENV{PERL_LOCAL_LIB_ROOT} = $ENV{_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT} if defined($ENV{_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT"}B= not $nondestructive
ABresult
1X1
011
000
144 0 undef $ENV{_OLD_PERL_VIRTUAL_PERL_LOCAL_LIB_ROOT};
145  
146 0 ▶ $ENV{PERL_MB_OPT} = $ENV{_OLD_PERL_VIRTUAL_PERL_MB_OPT} if defined($ENV{_OLD_PERL_VIRTUAL_PERL_MB_OPT}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MB_OPT"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MB_OPT"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MB_OPT"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MB_OPT"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MB_OPT"}B= not $nondestructive
ABresult
1X1
011
000
147 0 undef $ENV{_OLD_PERL_VIRTUAL_PERL_MB_OPT};
148  
149 0 ▶ $ENV{PERL_MM_OPT} = $ENV{_OLD_PERL_VIRTUAL_PERL_MM_OPT} if defined($ENV{_OLD_PERL_VIRTUAL_PERL_MM_OPT}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MM_OPT"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MM_OPT"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MM_OPT"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MM_OPT"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PERL_MM_OPT"}B= not $nondestructive
ABresult
1X1
011
000
150 0 undef $ENV{_OLD_PERL_VIRTUAL_PERL_MM_OPT};
151  
152 0 ▶ $ENV{PS1} = $ENV{_OLD_PERL_VIRTUAL_PS1} if defined($ENV{_OLD_PERL_VIRTUAL_PS1}) or not $nondestructive;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"_OLD_PERL_VIRTUAL_PS1"} or not $nondestructive 0 0 0
Condition0%0/3
defined $ENV{"_OLD_PERL_VIRTUAL_PS1"} or not $nondestructive
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ENV{"_OLD_PERL_VIRTUAL_PS1"} or not $nondestructive
defined $ENV{"_OLD_PERL_VIRTUAL_PS1"} not $nondestructive
Truth table0%0/3
A or not(B)
A= defined $ENV{"_OLD_PERL_VIRTUAL_PS1"}B= not $nondestructive
ABresult
1X1
011
000
153 0 undef $ENV{_OLD_PERL_VIRTUAL_PS1};
154  
155 0 return 1;
156 }
157  
158 =head2 create($virtualenv_path, $empty)
159  
160 creates Perl virtual environment
161  
162 $virtualenv_path: I<new virtual environment path>
163  
164 $empty: I<create empty virtual environment>
165  
166 return value: I<virtual environment path if success, otherwise undef>
167  
168 =cut
169 sub create
170 0 ▶{
Subroutine create: not called CC=4 SCAR=30.0
Pod documented
171 0 my ($virtualenv_path, $empty) = @_;
172 0 ▶ return unless defined($virtualenv_path) and length($virtualenv_path) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $virtualenv_path and length $virtualenv_path > 0 0 0 0
Condition0%0/3
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $virtualenv_path and length $virtualenv_path > 0
defined $virtualenv_path length $virtualenv_path > 0
Truth table0%0/3
A and B
A= defined $virtualenv_pathB= length $virtualenv_path > 0
ABresult
0X0
100
111
173 0 $virtualenv_path = Cwd::realpath($virtualenv_path);
174 0 say "Creating Perl virtual environment: $virtualenv_path";
175  
176 0 deactivate();
177 0 $ENV{PERL_MM_USE_DEFAULT} = 1;
178 0 $ENV{NONINTERACTIVE_TESTING} = 1;
179 0 $ENV{AUTOMATED_TESTING} = 1;
180  
181 0 require local::lib;
182 0 local::lib->import($virtualenv_path);
183  
184 0 activate($virtualenv_path);
185  
186 0 ▶ perl("-MCPAN", "-e exit(defined(CPAN::Shell->force('install', 'CPAN'))? 0: 1);") unless $empty;
Branch: 1 branch
BranchTrueFalseTotal
unless $empty 0 0 0
187  
188 0 my $pkg_path = dirname(__FILE__);
189  
190 0 say "Copying... bin/activate";
191 0 copy("$pkg_path/Virtualenv/activate", "$virtualenv_path/bin/activate");
192 0 chmod(0644, "$virtualenv_path/bin/activate");
193  
194 0 say "Copying... bin/sh.pl";
195 0 copy("$pkg_path/Virtualenv/sh.pl", "$virtualenv_path/bin/sh.pl");
196 0 chmod(0755, "$virtualenv_path/bin/sh.pl");
197  
198 0 say "Copying... bin/perl.pl";
199 0 file_put_contents("$virtualenv_path/bin/perl.pl", "#!".shellmeta($Config{perlpath})."\n".file_get_contents("$pkg_path/Virtualenv/perl.pl"));
200 0 chmod(0755, "$virtualenv_path/bin/perl.pl");
201 0 symlink("perl.pl", "$virtualenv_path/bin/perl");
202  
203 0 say "Copying... bin/virtualenv.pl";
204 0 copy("$pkg_path/Virtualenv/virtualenv.pl", "$virtualenv_path/bin/virtualenv.pl");
205 0 chmod(0755, "$virtualenv_path/bin/virtualenv.pl");
206 0 symlink("virtualenv.pl", "$virtualenv_path/bin/virtualenv");
207  
208 0 return $virtualenv_path;
209 }
210  
211 =head2 find_virtualenv_path($virtualenv_path)
212  
213 finds Perl virtual environment path by $virtualenv_path argument or activated virtual environment or running script or PERL5LIB environment variable
214  
215 $virtualenv_path: I<virtual environment path>
216  
217 return value: I<best matching virtual environment path>
218  
219 =cut
220 sub find_virtualenv_path
221 0 ▶{
Subroutine find_virtualenv_path: not called CC=17 SCAR=57.2
Pod documented
222 0 my ($virtualenv_path) = @_;
223 0 ▶ $virtualenv_path = $ENV{PERL_VIRTUAL_ENV} if not (defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5");
Branch: 1 branch
BranchTrueFalseTotal
unless defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5" 0 0 0
Condition0%0/6
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5"
Truth table0%0/4
A and B and C
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"
ABCresult
0XX0
10X0
1100
1111
224 0 ▶ $virtualenv_path = "${FindBin::Bin}/.." if not (defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5") and ${FindBin::Bin} !~ qr'^(/usr/|/bin/)' and -d "${FindBin::Bin}/../lib/perl5";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $virtualenv_path && length $virtualenv_path > 0 && -d "$virtualenv_path/lib/perl5" || $FindBin::Bin =~ qr"^(/usr/|/bin/)" and -d "$FindBin::Bin/../lib/perl5" 0 0 0
Condition0%0/12
not defined $virtualenv_path && length $virtualenv_path > 0 && -d "$virtualenv_path/lib/perl5" || $FindBin::Bin =~ qr"^(/usr/|/bin/)" and -d "$FindBin::Bin/../lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path && length $virtualenv_path > 0 && -d "$virtualenv_path/lib/perl5" || $FindBin::Bin =~ qr"^(/usr/|/bin/)"
l!l&&r!l&&!r
000
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/5
not defined $virtualenv_path && length $virtualenv_path > 0 && -d "$virtualenv_path/lib/perl5" || $FindBin::Bin =~ qr"^(/usr/|/bin/)" and -d "$FindBin::Bin/../lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5" $FindBin::Bin =~ qr"^(/usr/|/bin/)" -d "$FindBin::Bin/../lib/perl5"
Truth table0%0/10
not(A and B and C || D) and E
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"D= $FindBin::Bin =~ qr"^(/usr/|/bin/)"E= -d "$FindBin::Bin/../lib/perl5"
ABCDEresult
111XX0
0XX1X0
10X1X0
1101X0
0XX000
10X000
110000
0XX011
10X011
110011
225 0 ▶ for (split(":", defined($ENV{PERL5LIB})? $ENV{PERL5LIB}: ""))
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL5LIB'} ? : 0 0 0
226 {
227 0 ▶ last if defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5";
Branch: 1 branch
BranchTrueFalseTotal
if defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5" 0 0 0
Condition0%0/6
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5"
Truth table0%0/4
A and B and C
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"
ABCresult
0XX0
10X0
1100
1111
228 0 $virtualenv_path = "$_/../..";
229 }
230 0 ▶ return if not (defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5");
Branch: 1 branch
BranchTrueFalseTotal
unless defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5" 0 0 0
Condition0%0/6
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5"
Truth table0%0/4
A and B and C
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"
ABCresult
0XX0
10X0
1100
1111
231 0 return $virtualenv_path;
232 }
233  
234 =head2 activate2($virtualenv_path, $inform)
235  
236 activates Perl virtual environment by find_virtualenv_path function
237  
238 $virtualenv_path: I<virtual environment path>
239  
240 $inform: I<informs activated virtual environment path to STDERR if new activated path differs old one, by default 0>
241  
242 return value: I<activated best matching virtual environment path if success, otherwise undef>
243  
244 =cut
245 sub activate2
246 0 ▶{
Subroutine activate2: not called CC=5 SCAR=34.0
Pod documented
247 0 my ($virtualenv_path, $inform) = @_;
248 0 my $old_virtualenv_path = $ENV{PERL_VIRTUAL_ENV};
249 0 $virtualenv_path = activate(find_virtualenv_path($virtualenv_path));
250 0 ▶ if ($inform)
Branch: 1 branch
BranchTrueFalseTotal
if ($inform) 0 0 0
251 {
252 0 ▶ if (defined($virtualenv_path))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $virtualenv_path) { } 0 0 0
253 {
254 0 ▶ say STDERR "Perl virtual environment path: $virtualenv_path" if not defined $old_virtualenv_path or $old_virtualenv_path ne $virtualenv_path;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $old_virtualenv_path or $old_virtualenv_path ne $virtualenv_path 0 0 0
Condition0%0/3
not defined $old_virtualenv_path or $old_virtualenv_path ne $virtualenv_path
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $old_virtualenv_path or $old_virtualenv_path ne $virtualenv_path
not defined $old_virtualenv_path $old_virtualenv_path ne $virtualenv_path
Truth table0%0/3
not(A) or B
A= not defined $old_virtualenv_pathB= $old_virtualenv_path ne $virtualenv_path
ABresult
1X1
011
000
255 } else
256 {
257 0 say STDERR "Perl virtual environment is not activated";
258 }
259 }
260 0 return $virtualenv_path;
261 }
262  
263 =head2 getinc($virtualenv_path)
264  
265 gets array ref of include paths given virtual environment path or sitelib paths
266  
267 $virtualenv_path: I<virtual environment path>
268  
269 return value: I<array ref of paths>
270  
271 =cut
272 sub getinc
273 0 ▶{
Subroutine getinc: not called CC=7 SCAR=40.3
Pod documented
274 0 my ($virtualenv_path) = @_;
275 0 my $perl5lib;
276 0 ▶ $perl5lib = "$virtualenv_path/lib/perl5" if defined($virtualenv_path) and length($virtualenv_path) > 0 and -d "$virtualenv_path/lib/perl5";
Branch: 1 branch
BranchTrueFalseTotal
if defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5" 0 0 0
Condition0%0/6
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
!ll&&!rl&&r
000
defined $virtualenv_path and length $virtualenv_path > 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $virtualenv_path and length $virtualenv_path > 0 and -d "$virtualenv_path/lib/perl5"
defined $virtualenv_path length $virtualenv_path > 0 -d "$virtualenv_path/lib/perl5"
Truth table0%0/4
A and B and C
A= defined $virtualenv_pathB= length $virtualenv_path > 0C= -d "$virtualenv_path/lib/perl5"
ABCresult
0XX0
10X0
1100
1111
277 0 ▶ my $inc = [(defined($perl5lib)? ("$perl5lib/$Config{version}/$Config{archname}", "$perl5lib/$Config{version}", "$perl5lib/$Config{archname}", "$perl5lib"): ($Config{sitearch}, $Config{sitelib}))];
Branch: 1 branch
BranchTrueFalseTotal
defined $perl5lib ? : 0 0 0
278 0 ▶ @$inc = map(((length($_) < 1 or substr($_, -1, 1) ne "/")? "$_/": $_), @$inc);
Branch: 1 branch
BranchTrueFalseTotal
length $_ < 1 || substr($_, -1, 1) ne '/' ? : 0 0 0
Condition0%0/3
length $_ < 1 or substr($_, -1, 1) ne "/"
l!l&&r!l&&!r
000
MC/DC0%0/2
length $_ < 1 or substr($_, -1, 1) ne "/"
length $_ < 1 substr($_, -1, 1) ne "/"
Truth table0%0/3
A or B
A= length $_ < 1B= substr($_, -1, 1) ne "/"
ABresult
1X1
011
000
279 0 return $inc;
280 }
281  
282 =head2 list(%params)
283  
284 lists packages or modules or files by given %params
285  
286 %params: I<parameters of function>
287  
288 =over
289  
290 one: I<output is one-column, by default 0>
291  
292 detail: I<prints additional detail by given value('module' or 'file'), by default undef>
293  
294 =back
295  
296 return value: I<always 1>
297  
298 =cut
299 sub list
300 0 ▶{
Subroutine list: not called CC=15 SCAR=54.8
Pod documented
301 0 my %params = @_;
302 0 my $inc = getinc(activate2(undef, 1));
303 0 my $inst = ExtUtils::Installed->new(inc_override => $inc, extra_libs =>[]);
304 0 my @packages = sort({lc($a) cmp lc($b)} $inst->modules());
305 0 ▶ for my $package_name (grep({ my $package = $_; not defined($params{packages}) or not @{$params{packages}} or grep($_ eq $package, @{$params{packages}}) } @packages))
Condition0%0/6
!(defined $params{'packages'} && @{$params{'packages'};}) || grep(($_ eq $package), @{$params{'packages'};})
l!l&&r!l&&!r
000
defined $params{'packages'} && @{$params{'packages'};}
!ll&&!rl&&r
000
MC/DC0%0/3
!(defined $params{'packages'} && @{$params{'packages'};}) || grep(($_ eq $package), @{$params{'packages'};})
defined $params{'packages'} @{$params{'packages'};} grep(($_ eq $package), @{$params{'packages'};})
Truth table0%0/4
not(A && B) || C
A= defined $params{'packages'}B= @{$params{'packages'};}C= grep(($_ eq $package), @{$params{'packages'};})
ABCresult
0XX1
10X1
1111
1100
306 {
307 0 ▶ next if $package_name eq 'Perl';
Branch: 1 branch
BranchTrueFalseTotal
if $package_name eq "Perl" 0 0 0
308 0 my $version = $inst->version($package_name);
309 0 ▶ $version = "0" if not $version;
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 0 0
310 0 ▶ if ($params{detail})
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"detail"}) 0 0 0
311 {
312 0 ▶ say sprintf("%-40s %10s", $package_name, $version) unless $params{one};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"one"} 0 0 0
313 0 my @files = sort({lc($a) cmp lc($b)} $inst->files($package_name, "all"));
314 0 my $packlist_file = $inst->packlist($package_name)->packlist_file();
315 0 ▶ unshift @files, $packlist_file if defined($packlist_file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $packlist_file 0 0 0
316 0 for my $file (@files)
317 {
318 0 my $inc_path = (grep($file =~ /^\Q$_\E/, @$inc))[0];
319 0 ▶ my $rel_path = ($file =~ /^\Q$inc_path\E(.*)\.pm$/)[0] if defined($inc_path);
Branch: 1 branch
BranchTrueFalseTotal
if defined $inc_path 0 0 0
320 0 given ($params{detail})
321 {
322 when ("module")
323 0 {
324 0 ▶ if (defined($rel_path))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rel_path) 0 0 0
325 {
326 0 my $module = $rel_path;
327 0 $module =~ s/\//::/g;
328 0 ▶ print " " unless $params{one};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"one"} 0 0 0
329 0 say $module;
330 }
331 }
332 when ("file")
333 0 {
334 0 ▶ print " " unless $params{one};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"one"} 0 0 0
335 0 say $file;
336 }
337 }
338 }
339 0 next;
340 }
341 0 ▶ if ($params{one})
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"one"}) 0 0 0
342 {
343 0 say $package_name;
344 0 next;
345 }
346 0 say sprintf("%-40s %10s", $package_name, $version);
347 }
348 0 return 1;
349 }
350  
351 =head2 main(@argv)
352  
353 App::Virtualenv main function to run on command-line
354  
355 See also: L<virtualenv.pl|https://metacpan.org/pod/distribution/App-Virtualenv/lib/App/Virtualenv/virtualenv.pl>
356  
357 @argv: I<command-line arguments>
358  
359 return value: I<exit code of program>
360  
361 =cut
362 sub main
363 0 ▶{
Subroutine main: not called CC=17 SCAR=57.2
Pod documented
364 0 my (@argv) = @_;
365 0 my $args = cmdargs({ valuableArgs => 0, noCommand => 1 }, @argv);
366 0 my $cmd;
367 0 for my $arg (grep(/^\-/, keys %$args))
368 {
369 0 my $newcmd;
370 0 ▶ $newcmd = $arg if
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/ or $arg =~ /^\-(l|\-list)$/ or $arg =~ /^\-(m|\-list-modules)$/ or $arg =~ /^\-(f|\-list-files)$/ 0 0 0
Condition0%0/12
$arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/ or $arg =~ /^\-(l|\-list)$/ or $arg =~ /^\-(m|\-list-modules)$/ or $arg =~ /^\-(f|\-list-files)$/
l!l&&r!l&&!r
000
$arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/ or $arg =~ /^\-(l|\-list)$/ or $arg =~ /^\-(m|\-list-modules)$/
l!l&&r!l&&!r
000
$arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/ or $arg =~ /^\-(l|\-list)$/
l!l&&r!l&&!r
000
$arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/
l!l&&r!l&&!r
000
MC/DC0%0/5
$arg =~ /^\-(h|\-help)$/ or $arg =~ /^\-(c|\-create)$/ or $arg =~ /^\-(l|\-list)$/ or $arg =~ /^\-(m|\-list-modules)$/ or $arg =~ /^\-(f|\-list-files)$/
$arg =~ /^\-(h|\-help)$/ $arg =~ /^\-(c|\-create)$/ $arg =~ /^\-(l|\-list)$/ $arg =~ /^\-(m|\-list-modules)$/ $arg =~ /^\-(f|\-list-files)$/
Truth table0%0/6
A or B or C or D or E
A= $arg =~ /^\-(h|\-help)$/B= $arg =~ /^\-(c|\-create)$/C= $arg =~ /^\-(l|\-list)$/D= $arg =~ /^\-(m|\-list-modules)$/E= $arg =~ /^\-(f|\-list-files)$/
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
371 $arg =~ /^\-(h|\-help)$/ or
372 $arg =~ /^\-(c|\-create)$/ or
373 $arg =~ /^\-(l|\-list)$/ or
374 $arg =~ /^\-(m|\-list-modules)$/ or
375 $arg =~ /^\-(f|\-list-files)$/;
376 0 ▶ if (defined($newcmd))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newcmd) 0 0 0
377 {
378 0 ▶ die "Argument $newcmd doesn't use with $cmd.\n" if defined($cmd);
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmd 0 0 0
379 0 $cmd = $newcmd;
380 }
381 }
382 0 ▶ $cmd = "-c" unless defined($cmd);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cmd 0 0 0
383 0 given ($cmd)
384 {
385 when (/^\-(h|\-help)$/)
386 0 {
387 0 my @lines;
388 0 @lines = get_pod_text(dirname(__FILE__)."/Virtualenv/virtualenv.pl", "SYNOPSIS");
389 0 ▶ @lines = get_pod_text(dirname(__FILE__)."/Virtualenv/virtualenv.pl", "ABSTRACT") unless defined($lines[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lines[0] 0 0 0
390 0 $lines[0] = "virtualenv.pl";
391 0 say join("\n", @lines);
392 }
393 when (/^\-(c|\-create)$/)
394 0 {
395 0 ▶ die "Perl virtual environment path must be specified.\n" unless defined($args->{parameters}->[0]) and length($args->{parameters}->[0]) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"parameters"}[0] and length $args->{"parameters"}[0] > 0 0 0 0
Condition0%0/3
defined $args->{"parameters"}[0] and length $args->{"parameters"}[0] > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args->{"parameters"}[0] and length $args->{"parameters"}[0] > 0
defined $args->{"parameters"}[0] length $args->{"parameters"}[0] > 0
Truth table0%0/3
A and B
A= defined $args->{"parameters"}[0]B= length $args->{"parameters"}[0] > 0
ABresult
0X0
100
111
396 0 ▶ create($args->{parameters}->[0], (exists($args->{'-e'}) or exists($args->{'--empty'})));
Condition0%0/3
exists $args->{'-e'} || exists $args->{'--empty'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args->{'-e'} || exists $args->{'--empty'}
exists $args->{'-e'} exists $args->{'--empty'}
Truth table0%0/3
A || B
A= exists $args->{'-e'}B= exists $args->{'--empty'}
ABresult
1X1
011
000
397 }
398 when (/^\-(l|\-list)$/)
399 0 {
400 0 ▶ list(one => (exists($args->{'-1'}) or exists($args->{'--one'})), packages => $args->{parameters});
Condition0%0/3
exists $args->{'-1'} || exists $args->{'--one'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args->{'-1'} || exists $args->{'--one'}
exists $args->{'-1'} exists $args->{'--one'}
Truth table0%0/3
A || B
A= exists $args->{'-1'}B= exists $args->{'--one'}
ABresult
1X1
011
000
401 }
402 when (/^\-(m|\-list-modules)$/)
403 0 {
404 0 ▶ list(one => (exists($args->{'-1'}) or exists($args->{'--one'})), packages => $args->{parameters}, detail => 'module');
Condition0%0/3
exists $args->{'-1'} || exists $args->{'--one'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args->{'-1'} || exists $args->{'--one'}
exists $args->{'-1'} exists $args->{'--one'}
Truth table0%0/3
A || B
A= exists $args->{'-1'}B= exists $args->{'--one'}
ABresult
1X1
011
000
405 }
406 when (/^\-(f|\-list-files)$/)
407 0 {
408 0 ▶ list(one => (exists($args->{'-1'}) or exists($args->{'--one'})), packages => $args->{parameters}, detail => 'file');
Condition0%0/3
exists $args->{'-1'} || exists $args->{'--one'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args->{'-1'} || exists $args->{'--one'}
exists $args->{'-1'} exists $args->{'--one'}
Truth table0%0/3
A || B
A= exists $args->{'-1'}B= exists $args->{'--one'}
ABresult
1X1
011
000
409 }
410 }
411 0 return 0;
412 }
413  
414 =head2 run
415  
416 runs App::Virtualenv by main function with command-line arguments by @ARGV
417  
418 return value: I<function doesn't return, exits with main function return code>
419  
420 =cut
421 sub run
422 0 ▶{
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
423 0 exit main(@ARGV);
424 }
425  
426  
427 1 1;
428 __END__
↑ Summary lib/App/Virtualenv/Module.pm »