lib/Module/Install/Can.pm

filter: Statementstmt 24.3% 20 / 82 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 54.5% 6 / 11 Podpod 100% 4 / 4 totaltotal 20.6% 31 / 150 CC 21 SCAR 34.9
CC
21
Cov
17%
can_run
56.0
can_xs
56.0
can_cc
30.0
CRAP 32.6
« lib/Module/Install/Admin/Find.pm ↑ Summary lib/Module/Install/Bundle.pm »
1 package Module::Install::Can;
2  
3 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use ExtUtils::MakeMaker ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use Module::Install::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 46 ▶use vars qw{$VERSION @ISA $ISCORE};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 46 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 46 $VERSION = '1.21';
11 46 @ISA = 'Module::Install::Base';
12 46 $ISCORE = 1;
13 }
14  
15 # check if we can load some module
16 ### Upgrade this to not have to load the module if possible
17 0 ▶sub can_use {
Subroutine can_use: not called CC=3 SCAR=24.8
Pod documented
18 0 my ($self, $mod, $ver) = @_;
19 0 $mod =~ s{::|\\}{/}g;
20 0 ▶ $mod .= '.pm' unless $mod =~ /\.pm$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /\.pm$/i 0 0 0
21  
22 0 my $pkg = $mod;
23 0 $pkg =~ s{/}{::}g;
24 0 $pkg =~ s{\.pm$}{}i;
25  
26 0 local $@;
27 0 ▶ eval { require $mod; $pkg->VERSION($ver || 0); 1 };
Condition0%0/2
$ver || 0
l!l
00
MC/DC0%0/1
$ver || 0
$ver
Truth table0%0/2
A
A= $ver
Aresult
11
00
28 }
29  
30 # Check if we can run some command
31 0 ▶sub can_run {
Subroutine can_run: not called CC=7 SCAR=40.3
Pod documented
32 0 my ($self, $cmd) = @_;
33  
34 0 my $_cmd = $cmd;
35 0 ▶ return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
Branch: 1 branch
BranchTrueFalseTotal
if -x $_cmd or $_cmd = "MM"->maybe_command($_cmd) 0 0 0
Condition0%0/3
-x $_cmd or $_cmd = "MM"->maybe_command($_cmd)
l!l&&r!l&&!r
000
MC/DC0%0/2
-x $_cmd or $_cmd = "MM"->maybe_command($_cmd)
-x $_cmd $_cmd = "MM"->maybe_command($_cmd)
Truth table0%0/3
A or B
A= -x $_cmdB= $_cmd = "MM"->maybe_command($_cmd)
ABresult
1X1
011
000
36  
37 0 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
38 0 ▶ next if $dir eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "" 0 0 0
39 0 require File::Spec;
40 0 my $abs = File::Spec->catfile($dir, $cmd);
41 0 ▶ return $abs if (-x $abs or $abs = MM->maybe_command($abs));
Branch: 1 branch
BranchTrueFalseTotal
if -x $abs or $abs = "MM"->maybe_command($abs) 0 0 0
Condition0%0/3
-x $abs or $abs = "MM"->maybe_command($abs)
l!l&&r!l&&!r
000
MC/DC0%0/2
-x $abs or $abs = "MM"->maybe_command($abs)
-x $abs $abs = "MM"->maybe_command($abs)
Truth table0%0/3
A or B
A= -x $absB= $abs = "MM"->maybe_command($abs)
ABresult
1X1
011
000
42 }
43  
44 0 return;
45 }
46  
47 # Can our C compiler environment build XS files
48 0 ▶sub can_xs {
Subroutine can_xs: not called CC=7 SCAR=40.3
Pod documented
49 0 my $self = shift;
50  
51 # Ensure we have the CBuilder module
52 0 $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 );
53  
54 # Do we have the configure_requires checker?
55 0 local $@;
56 0 eval "require ExtUtils::CBuilder;";
57 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
58 # They don't obey configure_requires, so it is
59 # someone old and delicate. Try to avoid hurting
60 # them by falling back to an older simpler test.
61 0 return $self->can_cc();
62 }
63  
64 # Do we have a working C compiler
65 0 my $builder = ExtUtils::CBuilder->new(
66 quiet => 1,
67 );
68 0 ▶ unless ( $builder->have_compiler ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($builder->have_compiler) 0 0 0
69 # No working C compiler
70 0 return 0;
71 }
72  
73 # Write a C file representative of what XS becomes
74 0 require File::Temp;
75 0 my ( $FH, $tmpfile ) = File::Temp::tempfile(
76 "compilexs-XXXXX",
77 SUFFIX => '.c',
78 );
79 0 binmode $FH;
80 0 print $FH <<'END_C';
81 #include "EXTERN.h"
82 #include "perl.h"
83 #include "XSUB.h"
84  
85 int main(int argc, char **argv) {
86 return 0;
87 }
88  
89 int boot_sanexs() {
90 return 1;
91 }
92  
93 END_C
94 0 close $FH;
95  
96 # Can the C compiler access the same headers XS does
97 0 my @libs = ();
98 0 my $object = undef;
99 0 eval {
100 0 local $^W = 0;
101 0 $object = $builder->compile(
102 source => $tmpfile,
103 );
104 0 @libs = $builder->link(
105 objects => $object,
106 module_name => 'sanexs',
107 );
108 };
109 0 ▶ my $result = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
110  
111 # Clean up all the build files
112 0 foreach ( $tmpfile, $object, @libs ) {
113 0 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
114 0 ▶ 1 while unlink;
Branch: 1 branch
BranchTrueFalseTotal
unlink $_ and do { '???' } 0 0 0
115 }
116  
117 0 return $result;
118 }
119  
120 # Can we locate a (the) C compiler
121 0 ▶sub can_cc {
Subroutine can_cc: not called CC=5 SCAR=34.0
Pod documented
122 0 my $self = shift;
123  
124 0 ▶ if ($^O eq 'VMS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "VMS") 0 0 0
125 0 require ExtUtils::CBuilder;
126 0 my $builder = ExtUtils::CBuilder->new(
127 quiet => 1,
128 );
129 0 return $builder->have_compiler;
130 }
131  
132 0 ▶ my @chunks = split(/ /, $Config::Config{cc}) or return;
Branch: 1 branch
BranchTrueFalseTotal
my @chunks = split(/ /, $Config::Config{"cc"}, 0) or return 0 0 0
133  
134 # $Config{cc} may contain args; try to find out the program part
135 0 ▶ while (@chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chunks) 0 0 0
136 0 ▶ return $self->can_run("@chunks") || (pop(@chunks), next);
Condition0%0/3
$self->can_run(join($", @chunks)) || (pop @chunks, next)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->can_run(join($", @chunks)) || (pop @chunks, next)
$self->can_run(join($", @chunks)) (pop @chunks, next)
Truth table0%0/3
A || B
A= $self->can_run(join($", @chunks))B= (pop @chunks, next)
ABresult
1X1
011
000
137 }
138  
139 0 return;
140 }
141  
142 # Fix Cygwin bug on maybe_command();
143 46 ▶if ( $^O eq 'cygwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "cygwin") 0 46 46
144 0 require ExtUtils::MM_Cygwin;
145 0 require ExtUtils::MM_Win32;
146 0 ▶ if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &ExtUtils::MM_Cygwin::maybe_command) 0 0 0
147 0 ▶ *ExtUtils::MM_Cygwin::maybe_command = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
148 0 my ($self, $file) = @_;
149 0 ▶ if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[^/cygdrive/]i and 'ExtUtils::MM_Win32'->can('maybe_command')) { } 0 0 0
Condition0%0/3
$file =~ m[^/cygdrive/]i and "ExtUtils::MM_Win32"->can("maybe_command")
!ll&&!rl&&r
000
MC/DC0%0/2
$file =~ m[^/cygdrive/]i and "ExtUtils::MM_Win32"->can("maybe_command")
$file =~ m[^/cygdrive/]i "ExtUtils::MM_Win32"->can("maybe_command")
Truth table0%0/3
A and B
A= $file =~ m[^/cygdrive/]iB= "ExtUtils::MM_Win32"->can("maybe_command")
ABresult
0X0
100
111
150 0 ExtUtils::MM_Win32->maybe_command($file);
151 } else {
152 0 ExtUtils::MM_Unix->maybe_command($file);
153 }
154 }
155 0 }
156 }
157  
158 46 1;
159  
160 __END__
« lib/Module/Install/Admin/Find.pm ↑ Summary lib/Module/Install/Bundle.pm »