blib/lib/Probe/Perl.pm

filter: Statementstmt 80.8% 55 / 68 Branchbran 38.2% 13 / 34 Conditioncond 36.3% 4 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 13 / 13 Podpod 100% 9 / 9 totaltotal 66.9% 95 / 142 CC 24 SCAR 29.7
CC
24
Cov
64%
find_perl_interpreter
64.2
_backticks
10.3
config
5.2
CRAP 19.6
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Probe::Perl;
4 {
5 1 $Probe::Perl::VERSION = '0.03';
6 }
7  
8 # TODO: cache values derived from launching an external perl process
9 # TODO: docs refer to Config.pm and $self->{config}
10  
11  
12 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
16 1 my $class = shift;
17 1 ▶ my $data = shift || {};
Condition50%1/2
shift() || {}
l!l
01
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
18 1 return bless( $data, $class );
19 }
20  
21 8 ▶sub config {
Subroutine config: called CC=5 SCAR=16.5
Pod documented
22 8 my ($self, $key) = (shift, shift);
23 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 6 8
24 2 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 2 2
25 0 die "Can't set config values via $self->config(). Use $self->new() to create a local view";
26 }
27 2 $self->{$key} = shift;
28 }
29 8 ▶ return ref($self) && exists $self->{$key} ? $self->{$key} : $Config{$key};
Branch: 1 branch
BranchTrueFalseTotal
ref $self && exists $self->{$key} ? : 4 4 8
Condition66%2/3
ref $self and exists $self->{$key}
!ll&&!rl&&r
044
MC/DC50%1/2
ref $self and exists $self->{$key}
ref $self exists $self->{$key}
Truth table66%2/3
A and B
A= ref $selfB= exists $self->{$key}
ABresult
0X0
100
111
30 }
31  
32 1 ▶sub config_revert {
Subroutine config_revert: called CC=3 SCAR=11.2
Pod documented
33 1 my $self = shift;
34 1 ▶ die "Can't use config_revert() as a class method" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
35
36 1 delete $self->{$_} foreach @_;
37 }
38  
39 2 ▶sub perl_version {
Subroutine perl_version: called CC=2 SCAR=7.2
Pod documented
40 2 my $self = shift;
41 # Check the current perl interpreter
42 # It's much more convenient to use $] here than $^V, but 'man
43 # perlvar' says I'm not supposed to. Bloody tyrant.
44 2 ▶ return $^V ? $self->perl_version_to_float(sprintf( "%vd", $^V )) : $];
Branch: 1 branch
BranchTrueFalseTotal
$^V ? : 2 0 2
45 }
46  
47 2 ▶sub perl_version_to_float {
Subroutine perl_version_to_float: called CC=1 SCAR=0.0
Pod documented
48 2 my ($self, $version) = @_;
49 2 $version =~ s/\./../; # Double up the first dot so the output has one dot remaining
50 2 $version =~ s/\.(\d+)/sprintf( '%03d', $1 )/eg;
51 2 return $version;
52 }
53  
54 3 ▶sub _backticks {
Subroutine _backticks: called CC=7 SCAR=23.3
55 3 my $perl = shift;
56 3 ▶ return unless -e $perl;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $perl 0 3 3
57  
58 3 my $fh;
59 3 ▶ eval {open $fh, '-|', $perl, @_ or die $!};
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "-|", $perl, @_ or die $! 3 0 3
60 3 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 3 0 3
61 3 ▶ return <$fh> if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 2 1 3
62 1 my $tmp = do {local $/=undef; <$fh>};
63 1 return $tmp;
64 }
65  
66 # Quoting only happens on the path to perl - I control the rest of
67 # the args and they don't need quoting.
68 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
69 0 ▶ $perl = qq{"$perl"} if $perl =~ m{^[\w\\]+$};
Branch: 1 branch
BranchTrueFalseTotal
if $perl =~ /^[\w\\]+$/ 0 0 0
70 } else {
71 0 $perl =~ s{([^\w\\])}{\\$1}g;
72 }
73  
74 0 return `$perl @_`;
75 }
76  
77 1 ▶sub perl_is_same {
Subroutine perl_is_same: called CC=1 SCAR=0.0
Pod documented
78 1 my ($self, $perl) = @_;
79 1 return _backticks($perl, qw(-MConfig=myconfig -e print -e myconfig)) eq Config->myconfig;
80 }
81  
82 4 ▶sub find_perl_interpreter {
Subroutine find_perl_interpreter: called CC=9 SCAR=41.6
Pod documented
83 4 my $self = shift;
84  
85 4 ▶ return $^X if File::Spec->file_name_is_absolute($^X);
Branch: 1 branch
BranchTrueFalseTotal
if "File::Spec"->file_name_is_absolute($^X) 4 0 4
86  
87 0 my $exe = $self->config('exe_ext');
88  
89 0 my $thisperl = $^X;
90 0 ▶ if ($self->os_type eq 'VMS') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->os_type eq 'VMS') { } 0 0 0
elsif (defined $exe) { } 0 0 0
91 # VMS might have a file version at the end
92 0 ▶ $thisperl .= $exe unless $thisperl =~ m/$exe(;\d+)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $thisperl =~ /$exe(;\d+)?$/i 0 0 0
93 } elsif (defined $exe) {
94 0 ▶ $thisperl .= $exe unless $thisperl =~ m/$exe$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $thisperl =~ /$exe$/i 0 0 0
95 }
96  
97 0 foreach my $perl ( $self->config('perlpath'),
98 map( File::Spec->catfile($_, $thisperl),
99 File::Spec->path() )
100 ) {
101 0 ▶ return $perl if -f $perl and $self->perl_is_same($perl);
Branch: 1 branch
BranchTrueFalseTotal
if -f $perl and $self->perl_is_same($perl) 0 0 0
Condition0%0/3
-f $perl and $self->perl_is_same($perl)
!ll&&!rl&&r
000
MC/DC0%0/2
-f $perl and $self->perl_is_same($perl)
-f $perl $self->perl_is_same($perl)
Truth table0%0/3
A and B
A= -f $perlB= $self->perl_is_same($perl)
ABresult
0X0
100
111
102 }
103 0 return;
104 }
105  
106 # Determine the default @INC for this Perl
107 2 ▶sub perl_inc {
Subroutine perl_inc: called CC=1 SCAR=0.0
Pod documented
108 2 my $self = shift;
109  
110 2 local $ENV{PERL5LIB}; # this is not considered part of the default.
111  
112 2 my $perl = $self->find_perl_interpreter();
113  
114 2 my @inc = _backticks($perl, qw(-l -e print -e for -e @INC));
115 2 chomp @inc;
116  
117 2 return @inc;
118 }
119  
120  
121 {
122 1 my %OSTYPES = qw(
123 aix Unix
124 bsdos Unix
125 dgux Unix
126 dynixptx Unix
127 freebsd Unix
128 linux Unix
129 hpux Unix
130 irix Unix
131 darwin Unix
132 machten Unix
133 next Unix
134 openbsd Unix
135 netbsd Unix
136 dec_osf Unix
137 svr4 Unix
138 svr5 Unix
139 sco_sv Unix
140 unicos Unix
141 unicosmk Unix
142 solaris Unix
143 sunos Unix
144 cygwin Unix
145 os2 Unix
146  
147 dos Windows
148 MSWin32 Windows
149  
150 os390 EBCDIC
151 os400 EBCDIC
152 posix-bc EBCDIC
153 vmesa EBCDIC
154  
155 MacOS MacOS
156 VMS VMS
157 VOS VOS
158 riscos RiscOS
159 amigaos Amiga
160 mpeix MPEiX
161 );
162  
163  
164 2 ▶ sub os_type {
Subroutine os_type: called CC=2 SCAR=8.1
Pod documented
165 2 my $class = shift;
166 2 ▶ return $OSTYPES{shift || $^O};
Condition33%1/3
shift() || $^O
l!l&&r!l&&!r
200
MC/DC0%0/2
shift() || $^O
shift() $^O
Truth table33%1/3
A || B
A= shift()B= $^O
ABresult
1X1
011
000
167 }
168 }
169  
170  
171 1 1;
172  
173 __END__
↑ Summary