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