Commit | Line | Data |
---|---|---|
fe3b3201 | 1 | #line 1 |
0d5e38d1 | 2 | package Module::Install::Can; |
ecac864a | 3 | |
0d5e38d1 | 4 | use strict; |
fe3b3201 | 5 | use Module::Install::Base; |
0d5e38d1 | 6 | use Config (); |
fe3b3201 | 7 | ### This adds a 5.005 Perl version dependency. |
8 | ### This is a bug and will be fixed. | |
9 | use File::Spec (); | |
0d5e38d1 | 10 | use ExtUtils::MakeMaker (); |
11 | ||
fe3b3201 | 12 | use vars qw{$VERSION @ISA}; |
13 | BEGIN { | |
14 | $VERSION = '0.61'; | |
15 | @ISA = qw{Module::Install::Base}; | |
16 | } | |
17 | ||
18 | ||
ecac864a | 19 | # check if we can load some module |
fe3b3201 | 20 | ### Upgrade this to not have to load the module if possible |
ecac864a | 21 | sub can_use { |
fe3b3201 | 22 | my ($self, $mod, $ver) = @_; |
23 | $mod =~ s{::|\\}{/}g; | |
24 | $mod .= '.pm' unless $mod =~ /\.pm$/i; | |
ecac864a | 25 | |
fe3b3201 | 26 | my $pkg = $mod; |
27 | $pkg =~ s{/}{::}g; | |
28 | $pkg =~ s{\.pm$}{}i; | |
ecac864a | 29 | |
fe3b3201 | 30 | local $@; |
31 | eval { require $mod; $pkg->VERSION($ver || 0); 1 }; | |
ecac864a | 32 | } |
33 | ||
0d5e38d1 | 34 | # check if we can run some command |
35 | sub can_run { | |
fe3b3201 | 36 | my ($self, $cmd) = @_; |
0d5e38d1 | 37 | |
fe3b3201 | 38 | my $_cmd = $cmd; |
39 | return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); | |
0d5e38d1 | 40 | |
fe3b3201 | 41 | for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { |
42 | my $abs = File::Spec->catfile($dir, $_[1]); | |
43 | return $abs if (-x $abs or $abs = MM->maybe_command($abs)); | |
44 | } | |
0d5e38d1 | 45 | |
fe3b3201 | 46 | return; |
0d5e38d1 | 47 | } |
48 | ||
fe3b3201 | 49 | # can we locate a (the) C compiler |
0d5e38d1 | 50 | sub can_cc { |
fe3b3201 | 51 | my $self = shift; |
52 | my @chunks = split(/ /, $Config::Config{cc}) or return; | |
0d5e38d1 | 53 | |
fe3b3201 | 54 | # $Config{cc} may contain args; try to find out the program part |
55 | while (@chunks) { | |
56 | return $self->can_run("@chunks") || (pop(@chunks), next); | |
57 | } | |
0d5e38d1 | 58 | |
fe3b3201 | 59 | return; |
0d5e38d1 | 60 | } |
61 | ||
ecac864a | 62 | # Fix Cygwin bug on maybe_command(); |
fe3b3201 | 63 | if ( $^O eq 'cygwin' ) { |
64 | require ExtUtils::MM_Cygwin; | |
65 | require ExtUtils::MM_Win32; | |
66 | if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { | |
67 | *ExtUtils::MM_Cygwin::maybe_command = sub { | |
68 | my ($self, $file) = @_; | |
69 | if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { | |
70 | ExtUtils::MM_Win32->maybe_command($file); | |
71 | } else { | |
72 | ExtUtils::MM_Unix->maybe_command($file); | |
73 | } | |
74 | } | |
75 | } | |
ecac864a | 76 | } |
77 | ||
0d5e38d1 | 78 | 1; |
fe3b3201 | 79 | |
80 | __END__ | |
81 | ||
82 | #line 157 |