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